Spaces:
Paused
Paused
tomato
commited on
Commit
β’
17409ce
1
Parent(s):
7d93f13
use another kind of gradio interface
Browse files- app.py +19 -40
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
-
from tqdm import tqdm
|
4 |
import re
|
5 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
6 |
|
@@ -12,47 +10,28 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
|
12 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
13 |
|
14 |
def summarize(text):
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
input_ids=input_ids,
|
26 |
-
max_length=84,
|
27 |
-
no_repeat_ngram_size=2,
|
28 |
-
num_beams=4
|
29 |
-
)[0]
|
30 |
-
|
31 |
-
summary = tokenizer.decode(
|
32 |
-
output_ids,
|
33 |
-
skip_special_tokens=True,
|
34 |
-
clean_up_tokenization_spaces=False
|
35 |
-
)
|
36 |
return summary
|
37 |
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
<div>
|
49 |
-
Using summarization Model from <a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a>.
|
50 |
-
</div>
|
51 |
-
''')
|
52 |
-
text = gr.Textbox(label="Text here !!", lines=1, interactive=True)
|
53 |
-
summarize_btn = gr.Button("Let's Summarize",)
|
54 |
-
summarization = gr.Textbox()
|
55 |
-
html_output = gr.Markdown()
|
56 |
-
summarize_btn.click(summarize, [text], outputs=[html_output, summarization])
|
57 |
|
58 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import re
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
|
|
|
10 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
11 |
|
12 |
def summarize(text):
|
13 |
+
text = WHITESPACE_HANDLER(text)
|
14 |
|
15 |
+
inputs = tokenizer(text,
|
16 |
+
max_length=1024,
|
17 |
+
truncation=True,
|
18 |
+
return_tensors="pt")
|
19 |
+
|
20 |
+
summary_ids = model.generate(inputs["input_ids"])
|
21 |
+
summary = tokenizer.batch_decode(summary_ids,
|
22 |
+
skip_special_tokens=True,
|
23 |
+
clean_up_tokenization_spaces=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return summary
|
25 |
|
26 |
|
27 |
+
demo = gr.Interface(fn = summarize,
|
28 |
+
inputs = [gr.inputs.Textbox(lines=10,
|
29 |
+
placeholder="Inpuy something...",
|
30 |
+
label='Text here !!')],
|
31 |
+
outputs = [gr.outputs.Textbox(
|
32 |
+
label="Summary")],
|
33 |
+
|
34 |
+
title = "π Summarizer π",
|
35 |
+
enable_queue=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
gradio
|
2 |
torch
|
3 |
tqdm
|
4 |
-
transformers
|
|
|
|
1 |
gradio
|
2 |
torch
|
3 |
tqdm
|
4 |
+
transformers
|
5 |
+
sentencepiece
|