Spaces:
Sleeping
Sleeping
Download app.py from srinikesh1432/Text_summarization: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/srinikesh1432/Text_summarization/resolve/main/app.py
- Command line
-
hf download hf://spaces/srinikesh1432/Text_summarization/app.py
-
curl -L -o app.py https://huggingface.co/spaces/srinikesh1432/Text_summarization/resolve/main/app.py
1.08 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # Load summarization pipeline | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| def summarize_text(text, max_length=130, min_length=30): | |
| """ | |
| Summarizes the input text. | |
| """ | |
| if not text.strip(): | |
| return "Please enter some text to summarize." | |
| summary = summarizer( | |
| text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| do_sample=False | |
| )[0]["summary_text"] | |
| return summary | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=summarize_text, | |
| inputs=[ | |
| gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text"), | |
| gr.Slider(50, 200, value=130, step=10, label="Max Summary Length"), | |
| gr.Slider(20, 100, value=30, step=5, label="Min Summary Length") | |
| ], | |
| outputs=gr.Textbox(label="Summary"), | |
| title="Text Summarization App", | |
| description="Enter a long piece of text and get a concise summary using BART." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |