Spaces:
Sleeping
Sleeping
Download app.py from jackenmail/sentiment-analysis-app: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/jackenmail/sentiment-analysis-app/resolve/main/app.py
- Command line
-
hf download hf://spaces/jackenmail/sentiment-analysis-app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/jackenmail/sentiment-analysis-app/resolve/main/app.py
1.05 kB
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Load your model | |
| print("β³ Loading model...") | |
| classifier = pipeline("sentiment-analysis", model="jackenmail/sentiment-analysis") | |
| print("β Model ready!") | |
| def get_sentiment(text): | |
| if not text.strip(): | |
| return "β οΈ Please enter some text" | |
| result = classifier(text) | |
| label = result[0]["label"] | |
| score = round(result[0]["score"] * 100, 2) | |
| emoji = "π" if label == "POSITIVE" else "π" | |
| return f"{emoji} {label} ({score}% confidence)" | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn = get_sentiment, | |
| inputs = gr.Textbox(placeholder="Enter text here...", label="Input Text"), | |
| outputs = gr.Textbox(label="Sentiment Result"), | |
| title = "π― Sentiment Analysis", | |
| description = "Powered by jackenmail/sentiment-analysis", | |
| examples = [ | |
| ["I love this product!"], | |
| ["This is absolutely terrible."], | |
| ["Best purchase I ever made!"], | |
| ["I hate this, waste of money."] | |
| ] | |
| ) | |
| demo.launch() |