Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,13 @@
|
|
| 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 |
-
|
| 8 |
-
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 9 |
|
| 10 |
@spaces.GPU(duration=120)
|
| 11 |
-
def summarize(
|
| 12 |
-
|
| 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.Textbox(lines=7, label="Input Text"), outputs="text").launch(inline=False)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import spaces
|
| 3 |
+
from transformers import pipeline
|
| 4 |
|
| 5 |
model_name = 'Karzan/bart-summarization'
|
| 6 |
+
summarizer = pipeline("summarization", model=model_name)
|
|
|
|
| 7 |
|
| 8 |
@spaces.GPU(duration=120)
|
| 9 |
+
def summarize(text):
|
| 10 |
+
summary = summarizer(text, max_length=256, min_length=30, do_sample=False)[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
| 11 |
return summary
|
| 12 |
|
| 13 |
gr.Interface(fn=summarize, inputs=gr.Textbox(lines=7, label="Input Text"), outputs="text").launch(inline=False)
|