Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import transformers
|
| 3 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
| 4 |
+
|
| 5 |
+
model_name = 'facebook/bart-large-cnn'
|
| 6 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def summarize(inp):
|
| 10 |
+
inp = inp.replace('\n','')
|
| 11 |
+
inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
|
| 12 |
+
summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
|
| 13 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 14 |
+
return summary
|
| 15 |
+
|
| 16 |
+
app = gr.Interface(
|
| 17 |
+
fn=summarize,
|
| 18 |
+
inputs=gr.Textbox(lines=7, label="Input Text"),
|
| 19 |
+
outputs="text",
|
| 20 |
+
css="footer {visibility: hidden}",
|
| 21 |
+
article = """<p style='text-align: center;'>Hello, thanks for coming, visit AI tools: <a href="https://www.genelify.com" target="_blank">Genelify</a>, visit Social Media tools: <a href="https://www.tubtic.com" target="_blank">Tubtic</a></p>"""
|
| 22 |
+
)
|
| 23 |
+
app.launch(inline=False, show_api=False)
|