Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from textblob import TextBlob
|
| 3 |
+
|
| 4 |
+
# Streamlit page settings
|
| 5 |
+
st.set_page_config(page_title="Sentimental App", layout="centered")
|
| 6 |
+
|
| 7 |
+
# Title
|
| 8 |
+
st.title("π Sentimental App")
|
| 9 |
+
st.write("Analyze the sentiment of your text β positive, negative or neutral.")
|
| 10 |
+
|
| 11 |
+
# Input from user
|
| 12 |
+
user_input = st.text_area("Enter your text here:", height=150)
|
| 13 |
+
|
| 14 |
+
# Sentiment analysis function
|
| 15 |
+
def analyze_sentiment(text):
|
| 16 |
+
blob = TextBlob(text)
|
| 17 |
+
sentiment = blob.sentiment.polarity
|
| 18 |
+
if sentiment > 0:
|
| 19 |
+
return "Positive π"
|
| 20 |
+
elif sentiment < 0:
|
| 21 |
+
return "Negative π "
|
| 22 |
+
else:
|
| 23 |
+
return "Neutral π"
|
| 24 |
+
|
| 25 |
+
# Analyze button
|
| 26 |
+
if st.button("Analyze"):
|
| 27 |
+
if user_input.strip() == "":
|
| 28 |
+
st.warning("Please enter some text.")
|
| 29 |
+
else:
|
| 30 |
+
result = analyze_sentiment(user_input)
|
| 31 |
+
st.subheader("Sentiment Result:")
|
| 32 |
+
st.success(result)
|