Spaces:
Runtime error
Runtime error
inclusive-ml
commited on
Commit
•
270ad7b
1
Parent(s):
637ef73
initial commit
Browse files- app.py +13 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import transformers
|
3 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
4 |
+
model_name = 'facebook/bart-large-cnn'
|
5 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
6 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
7 |
+
def summarize(inp):
|
8 |
+
inp = inp.replace('\n','')
|
9 |
+
inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
|
10 |
+
summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
|
11 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
return summary
|
13 |
+
gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=7, label="Input Text"), outputs="text").launch(inline=False)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|