Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
+
|
| 6 |
+
# モデルとトークナイザーを読み込み
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("sonoisa/t5-base-japanese")
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("sonoisa/t5-base-japanese")
|
| 9 |
+
|
| 10 |
+
def summarize(text):
|
| 11 |
+
inputs = tokenizer("要約: " + text, return_tensors="pt", max_length=512, truncation=True)
|
| 12 |
+
summary_ids = model.generate(
|
| 13 |
+
inputs["input_ids"],
|
| 14 |
+
max_length=150,
|
| 15 |
+
min_length=30,
|
| 16 |
+
length_penalty=2.0,
|
| 17 |
+
num_beams=4,
|
| 18 |
+
early_stopping=True
|
| 19 |
+
)
|
| 20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 21 |
+
return summary
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
| 24 |
+
iface.launch()
|