Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
def summarize_text(text):
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
summary = summarizer(
|
| 7 |
+
text,
|
| 8 |
+
min_length=10,
|
| 9 |
+
max_length=100,
|
| 10 |
+
do_sample=False
|
| 11 |
+
)
|
| 12 |
+
return summary[0]['summary_text']
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("## Text Summarization Demo")
|
| 16 |
+
with gr.Row():
|
| 17 |
+
input_text = gr.Textbox(label="Enter your text here", placeholder="Paste your text here...", lines=5)
|
| 18 |
+
with gr.Row():
|
| 19 |
+
summarize_button = gr.Button("Summarize", variant="primary")
|
| 20 |
+
with gr.Row():
|
| 21 |
+
output_text = gr.Textbox(label="Summary", lines=4)
|
| 22 |
+
|
| 23 |
+
summarize_button.click(fn=summarize_text, inputs=input_text, outputs=output_text)
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch(share=True)
|