abhi227070
commited on
Commit
•
b7d8764
1
Parent(s):
cc14a20
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn")
|
6 |
+
|
7 |
+
def text_summarize(article):
|
8 |
+
|
9 |
+
inputs = tokenizer(article, return_tensors = 'pt')
|
10 |
+
|
11 |
+
output = model.generate(inputs.input_ids,
|
12 |
+
max_new_tokens = 200,
|
13 |
+
do_sample = True,
|
14 |
+
top_p = 0.9,
|
15 |
+
top_k = 50)
|
16 |
+
|
17 |
+
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
return output_text
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn = text_summarize,
|
23 |
+
inputs = gr.Textbox(label = "Article", lines = 8, placeholder = "Paste your text here.."),
|
24 |
+
outputs = gr.Textbox(label = "Summarized Text", lines = 5)
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|
28 |
+
|