Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# ใใผใฏใใคใถใผใจใขใใซใฎๆบๅ
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained('sonoisa/t5-base-japanese')
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained('models/')
|
8 |
+
|
9 |
+
|
10 |
+
def summary(text):
|
11 |
+
# ๆ็ซ ใใใณใฝใซใซๅคๆ
|
12 |
+
input = tokenizer.encode(text, return_tensors='pt', max_length=512, truncation=True)
|
13 |
+
# ๆจ่ซ
|
14 |
+
|
15 |
+
model.eval()
|
16 |
+
with torch.no_grad():
|
17 |
+
summary_ids = model.generate(input)
|
18 |
+
|
19 |
+
return tokenizer.decode(summary_ids[0][1:-1])]
|
20 |
+
|
21 |
+
descriptions = "T5ใซใใๆ็ซ ่ฆ็ดใๆ็ซ ใๅ
ฅๅใใใจใใใฎ่ฆ็ดๆใๅบๅใใพใใ"
|
22 |
+
|
23 |
+
demo = gr.Interface(fn=summary, inputs=gr.Textbox(lines=5, placeholder="ๆ็ซ ใๅ
ฅๅใใฆใใ ใใ"), outputs=gr.Textbox(lines=5),title="Sentence Summary", description=descriptions)
|
24 |
+
|
25 |
+
demo.launch()
|