Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="Sentiment Analyzer", page_icon="💬")
|
| 5 |
+
|
| 6 |
+
# Load sentiment analysis pipeline
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
return pipeline("sentiment-analysis")
|
| 10 |
+
|
| 11 |
+
sentiment_analyzer = load_model()
|
| 12 |
+
|
| 13 |
+
st.title("💬 Sentiment Analysis App")
|
| 14 |
+
st.write("Enter some text and the model will predict its sentiment.")
|
| 15 |
+
|
| 16 |
+
# User input
|
| 17 |
+
user_input = st.text_area("Enter your text here:", height=150)
|
| 18 |
+
|
| 19 |
+
# Button to analyze sentiment
|
| 20 |
+
if st.button("Analyze Sentiment"):
|
| 21 |
+
if user_input.strip() == "":
|
| 22 |
+
st.warning("⚠️ Please enter some text.")
|
| 23 |
+
else:
|
| 24 |
+
with st.spinner("Analyzing..."):
|
| 25 |
+
result = sentiment_analyzer(user_input)[0]
|
| 26 |
+
label = result['label']
|
| 27 |
+
score = result['score']
|
| 28 |
+
st.success(f"**Sentiment:** {label}")
|
| 29 |
+
st.info(f"**Confidence:** {score:.2f}")
|