Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load sentiment-analysis pipeline
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model():
|
| 7 |
+
return pipeline("sentiment-analysis")
|
| 8 |
+
|
| 9 |
+
analyzer = load_model()
|
| 10 |
+
|
| 11 |
+
# Streamlit app UI
|
| 12 |
+
st.title("🧠 Sentiment Analysis App")
|
| 13 |
+
st.write("Enter text to analyze the sentiment (Positive/Negative)")
|
| 14 |
+
|
| 15 |
+
user_input = st.text_area("Your text:")
|
| 16 |
+
|
| 17 |
+
if st.button("Analyze"):
|
| 18 |
+
if user_input.strip() == "":
|
| 19 |
+
st.warning("Please enter some text.")
|
| 20 |
+
else:
|
| 21 |
+
with st.spinner("Analyzing..."):
|
| 22 |
+
result = analyzer(user_input)
|
| 23 |
+
label = result[0]['label']
|
| 24 |
+
score = result[0]['score']
|
| 25 |
+
st.success(f"**Sentiment:** {label} \n**Confidence:** {score:.2f}")
|