Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# instantiate your summarization pipeline once
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn", tokenizer="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
def summarize(text, max_length=150, min_length=40):
|
| 8 |
+
# call the pipeline
|
| 9 |
+
result = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
|
| 10 |
+
return result[0]["summary_text"]
|
| 11 |
+
|
| 12 |
+
# build Gradio interface
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown("# 📝 Text Summarizer")
|
| 15 |
+
input_txt = gr.Textbox(lines=8, placeholder="Paste your article here…")
|
| 16 |
+
with gr.Row():
|
| 17 |
+
max_len = gr.Slider(50, 300, value=150, step=10, label="Max length")
|
| 18 |
+
min_len = gr.Slider(10, 100, value=40, step=5, label="Min length")
|
| 19 |
+
output_txt = gr.Textbox(lines=5, label="Summary")
|
| 20 |
+
btn = gr.Button("Summarize")
|
| 21 |
+
btn.click(fn=summarize, inputs=[input_txt, max_len, min_len], outputs=output_txt)
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
demo.launch()
|