Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
iface = gr.Interface(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 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()
|