aino813 commited on
Commit
ca79b72
โ€ข
1 Parent(s): b4601e2

Create new file

Browse files
Files changed (1) hide show
  1. app.py +25 -0
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()