Download app.py from WolfeLeo2/Test: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/WolfeLeo2/Test/resolve/main/app.py
- Command line
-
hf download hf://spaces/WolfeLeo2/Test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/WolfeLeo2/Test/resolve/main/app.py
1.25 kB
| import gradio as gr | |
| import logging | |
| import sys | |
| from transformers import pipeline | |
| # Configure logging | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
| logger = logging.getLogger(__name__) | |
| # Load the model | |
| logger.info("Loading bart-large-cnn model...") | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| logger.info("Model loaded successfully!") | |
| def summarize_text(text, max_length=150, min_length=30): | |
| if not text or len(text.strip()) < 50: | |
| return text | |
| logger.info(f"Summarizing text of length {len(text)}") | |
| result = summarizer( | |
| text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| truncation=True | |
| ) | |
| summary = result[0]["summary_text"] | |
| return summary | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=summarize_text, | |
| inputs=[ | |
| gr.Textbox(lines=10, label="Text to Summarize"), | |
| gr.Slider(50, 500, value=150, label="Max Length"), | |
| gr.Slider(10, 200, value=30, label="Min Length") | |
| ], | |
| outputs=gr.Textbox(label="Summary"), | |
| title="StudAI ", | |
| description="Powered by facebook/bart-large-cnn model" | |
| ) | |
| demo.launch(share=True, server_name="Leo", server_port=8000) |