Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the summarization model | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| def generate_summary(text): | |
| input_length = len(text.split()) | |
| max_length = min(200, input_length + 20) | |
| min_length = min(50, max_length // 2) | |
| summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=True, temperature=0.7) | |
| return summary[0]['summary_text'] | |
| # Define the Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_summary, | |
| inputs=gr.Textbox(lines=5, placeholder="Enter text here..."), | |
| outputs=gr.Textbox(label="Summary"), | |
| title="Text Summarization with Transformers", | |
| description="Enter a text passage, and the model will generate a summarized version." | |
| ) | |
| # Launch the GUI | |
| iface.launch() | |