Spaces:
Sleeping
Sleeping
Download sentiment_analysis.py from AIROBOHUB/Smart-AI-Tools: direct link, hf CLI and curl.
- Browser
- Download file 807 Bytes
-
https://huggingface.co/spaces/AIROBOHUB/Smart-AI-Tools/resolve/main/sentiment_analysis.py
- Command line
-
hf download hf://spaces/AIROBOHUB/Smart-AI-Tools/sentiment_analysis.py
-
curl -L -o sentiment_analysis.py https://huggingface.co/spaces/AIROBOHUB/Smart-AI-Tools/resolve/main/sentiment_analysis.py
807 Bytes
| import streamlit as st | |
| import torch | |
| # Use a pipeline as a high-level helper | |
| from transformers import pipeline | |
| text_classification = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english") | |
| def sentment_classifiction(text): | |
| output = text_classification(text) | |
| return output[0]['label'] | |
| # Streamlit UI | |
| def run(): | |
| st.title("Sentiment Analysis") | |
| st.write("Enter a comment below to analyze its sentiment.") | |
| text = st.text_area("Enter your text here:", "") | |
| if st.button("Analyze"): | |
| if text: | |
| with st.spinner("Analyzing the text..."): | |
| result = sentment_classifiction(text) | |
| st.success(f"**Sentiment:** {result}") | |
| else: | |
| st.warning("⚠️ Please enter some text for analysis.") |