| import gradio as gr | |
| from transformers import pipeline | |
| def summarize_text(text): | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| summary = summarizer( | |
| text, | |
| min_length=10, | |
| max_length=100, | |
| do_sample=False | |
| ) | |
| return summary[0]['summary_text'] | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Text Summarization Demo") | |
| with gr.Row(): | |
| input_text = gr.Textbox( | |
| label="Enter your text here", | |
| placeholder="Paste your text here...", | |
| lines=5 | |
| ) | |
| with gr.Row(): | |
| summarize_button = gr.Button("Summarize", variant="primary") | |
| with gr.Row(): | |
| output_text = gr.Textbox( | |
| label="Summary", | |
| lines=4 | |
| ) | |
| summarize_button.click( | |
| fn=summarize_text, | |
| inputs=input_text, | |
| outputs=output_text | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |