Spaces:
Sleeping
Sleeping
Download app.py from a7madmostafa/sentiment_analysis: direct link, hf CLI and curl.
- Browser
- Download file 808 Bytes
-
https://huggingface.co/spaces/a7madmostafa/sentiment_analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/a7madmostafa/sentiment_analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/a7madmostafa/sentiment_analysis/resolve/main/app.py
808 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Load model | |
| pipe = pipeline( | |
| "text-classification", | |
| model="distilbert/distilbert-base-uncased-finetuned-sst-2-english" | |
| ) | |
| # Inference function | |
| def classify_text(text): | |
| if not text.strip(): | |
| return "Please enter some text." | |
| result = pipe(text)[0] | |
| label = result["label"] | |
| score = round(result["score"], 4) | |
| return f"Sentiment: {label}\nConfidence: {score}" | |
| # Gradio UI | |
| app = gr.Interface( | |
| fn=classify_text, | |
| inputs=gr.Textbox( | |
| lines=4, | |
| placeholder="Type a sentence to analyze sentiment..." | |
| ), | |
| outputs=gr.Textbox(label="Result"), | |
| title="Sentiment Analysis App", | |
| description="Powered by DistilBERT (SST-2)\nClassifies text as POSITIVE or NEGATIVE." | |
| ) | |
| # Run app | |
| app.launch() | |