Spaces:
Sleeping
Sleeping
Download app.py from Snigs98/text-summarization-gui: direct link, hf CLI and curl.
- Browser
- Download file 824 Bytes
-
https://huggingface.co/spaces/Snigs98/text-summarization-gui/resolve/main/app.py
- Command line
-
hf download hf://spaces/Snigs98/text-summarization-gui/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Snigs98/text-summarization-gui/resolve/main/app.py
824 Bytes
| 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() | |