Spaces:
Sleeping
Sleeping
Download app.py from Atelv7/text-sentiment-classifier: direct link, hf CLI and curl.
- Browser
- Download file 561 Bytes
-
https://huggingface.co/spaces/Atelv7/text-sentiment-classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Atelv7/text-sentiment-classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Atelv7/text-sentiment-classifier/resolve/main/app.py
561 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # Load Hugging Face pretrained sentiment analysis model | |
| classifier = pipeline("sentiment-analysis") | |
| def classify_text(text): | |
| result = classifier(text)[0] | |
| return f"Label: {result['label']}, Confidence: {result['score']:.2f}" | |
| # Gradio interface | |
| gr.Interface( | |
| fn=classify_text, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="Sentiment Classifier", | |
| description="Type a sentence and get sentiment prediction (Positive or Negative)" | |
| ).launch() | |