Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,26 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
text = text.lower()
|
| 9 |
-
pos_count = sum(word in text for word in positive_words)
|
| 10 |
-
neg_count = sum(word in text for word in negative_words)
|
| 11 |
-
|
| 12 |
-
if pos_count > neg_count:
|
| 13 |
-
return "Positive 😊", pos_count, neg_count
|
| 14 |
-
elif neg_count > pos_count:
|
| 15 |
-
return "Negative 😞", pos_count, neg_count
|
| 16 |
-
else:
|
| 17 |
-
return "Neutral 😐", pos_count, neg_count
|
| 18 |
|
| 19 |
# Streamlit UI
|
| 20 |
-
st.title("
|
| 21 |
-
st.
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
if st.button("Analyze"):
|
| 26 |
-
if
|
| 27 |
-
st.warning("Please enter some text
|
| 28 |
else:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load sentiment-analysis pipeline from Hugging Face
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model():
|
| 7 |
+
return pipeline("sentiment-analysis")
|
| 8 |
|
| 9 |
+
sentiment_pipeline = load_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Streamlit UI
|
| 12 |
+
st.title("Smart Sentiment Analyzer 🤖")
|
| 13 |
+
st.markdown("Analyze your sentence using a real AI model (DistilBERT).")
|
| 14 |
|
| 15 |
+
text = st.text_area("Enter your sentence:")
|
| 16 |
|
| 17 |
+
if st.button("Analyze Sentiment"):
|
| 18 |
+
if text.strip() == "":
|
| 19 |
+
st.warning("Please enter some text.")
|
| 20 |
else:
|
| 21 |
+
result = sentiment_pipeline(text)[0]
|
| 22 |
+
label = result["label"]
|
| 23 |
+
score = round(result["score"] * 100, 2)
|
| 24 |
+
|
| 25 |
+
st.success(f"**Sentiment:** {label}")
|
| 26 |
+
st.info(f"**Confidence:** {score}%")
|