Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,18 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import transformers
|
| 3 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
| 4 |
+
import spaces
|
| 5 |
|
| 6 |
+
model_name = 'Karzan/bart-summarization'
|
| 7 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 9 |
|
| 10 |
+
@spaces.GPU(duration=120)
|
| 11 |
+
def summarize(inp):
|
| 12 |
+
inp = inp.replace('\n','')
|
| 13 |
+
inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
|
| 14 |
+
summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
|
| 15 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 16 |
+
return summary
|
| 17 |
+
|
| 18 |
+
gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=7, label="Input Text"), outputs="text").launch(inline=False)
|