kakitsubata commited on
Commit
c5480cd
·
verified ·
1 Parent(s): bd17397

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,18 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # 日本語T5モデルをロード
5
  pipe = pipeline("text2text-generation", model="sonoisa/t5-base-japanese")
6
 
7
  def format_report(memo):
8
- # プロンプトに「事故報告書風に整えてください」と指示を入れる
9
- input_text = f"以下のメモを事故報告書の文章に整えてください:\n{memo}"
10
- result = pipe(input_text, max_length=512, do_sample=False)
11
- return result[0]["generated_text"]
 
 
 
 
 
 
12
 
13
- iface = gr.Interface(fn=format_report,
14
- inputs="text",
15
- outputs="text",
16
- title="事故報告書整理AI")
 
 
 
17
 
18
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # 日本語T5モデルをロード(サイズは base。必要なら large に変更可)
5
  pipe = pipeline("text2text-generation", model="sonoisa/t5-base-japanese")
6
 
7
  def format_report(memo):
8
+ if not memo.strip():
9
+ return "⚠️ 入力が空です。事故メモを入力してください。"
10
+
11
+ # プロンプトを工夫して「報告書風」に整えるよう指示
12
+ input_text = f"以下のメモを特養での事故報告書の文章に整えてください。\n{memo}"
13
+ try:
14
+ result = pipe(input_text, max_length=512, do_sample=False)
15
+ return result[0]["generated_text"]
16
+ except Exception as e:
17
+ return f"⚠️ エラーが発生しました: {str(e)}"
18
 
19
+ iface = gr.Interface(
20
+ fn=format_report,
21
+ inputs=gr.Textbox(lines=8, placeholder="ここに事故のメモを入力してください"),
22
+ outputs="text",
23
+ title="事故報告書整理AI",
24
+ description="介護現場での事故メモを、報告書形式の文章に整えます。"
25
+ )
26
 
27
  iface.launch()