Spaces:
Runtime error
Runtime error
Commit Β·
f8cb31c
1
Parent(s): 1170100
Update app.py
Browse files- app/app.py +13 -27
app/app.py
CHANGED
|
@@ -1,33 +1,19 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import nltk
|
| 4 |
-
from nltk.corpus import stopwords
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
with open("model/logistic_model.pkl", "rb") as f:
|
| 11 |
-
model = pickle.load(f)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
vectorizer = pickle.load(f)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
st.title("π Twitter Sentiment Analysis")
|
| 20 |
-
st.write("Enter a tweet below to predict whether it's **Positive**, **Negative**, or **Neutral**.")
|
| 21 |
-
|
| 22 |
-
tweet = st.text_area("βοΈ Enter Tweet Text")
|
| 23 |
-
|
| 24 |
-
if st.button("Analyze Sentiment"):
|
| 25 |
-
if tweet.strip() == "":
|
| 26 |
-
st.warning("Please enter some text to analyze.")
|
| 27 |
else:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
st.success(f"π Sentiment: **{prediction.capitalize()}**")
|
| 33 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import joblib
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load vectorizer and model
|
| 5 |
+
vectorizer = joblib.load('model/tfidf_vectorizer.pkl')
|
| 6 |
+
model = joblib.load('model/logistic_model.pkl')
|
| 7 |
|
| 8 |
+
st.title("Twitter Sentiment Analysis")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
user_input = st.text_area("Enter text to analyze sentiment:")
|
|
|
|
| 11 |
|
| 12 |
+
if st.button("Predict Sentiment"):
|
| 13 |
+
if user_input.strip() == "":
|
| 14 |
+
st.warning("Please enter some text!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
else:
|
| 16 |
+
X = vectorizer.transform([user_input])
|
| 17 |
+
prediction = model.predict(X)
|
| 18 |
+
sentiment = "Positive π" if prediction[0] == 1 else "Negative π"
|
| 19 |
+
st.success(f"Predicted sentiment: {sentiment}")
|
|
|
|
|
|