Spaces:
Build error
Build error
Upload 4 files
Browse files- app.py +104 -0
- logistic_regression_model.pkl +3 -0
- requirements.txt +3 -0
- vectorizer.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load model and vectorizer
|
| 6 |
+
model = joblib.load('logistic_regression_model.pkl')
|
| 7 |
+
vect = joblib.load('vectorizer.pkl')
|
| 8 |
+
|
| 9 |
+
def sentiment_prediction(text):
|
| 10 |
+
text_arr = [text]
|
| 11 |
+
text_transformed = vect.transform(text_arr)
|
| 12 |
+
prediction = model.predict(text_transformed)
|
| 13 |
+
return prediction
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
st.set_page_config(page_title="🎬 Movie Review Sentiment Analysis", page_icon="🎭", layout="wide")
|
| 17 |
+
|
| 18 |
+
# Custom CSS for stylish UI
|
| 19 |
+
st.markdown("""
|
| 20 |
+
<style>
|
| 21 |
+
body {
|
| 22 |
+
background-color: #1e1e2f;
|
| 23 |
+
color: white;
|
| 24 |
+
}
|
| 25 |
+
.title {
|
| 26 |
+
font-size: 40px;
|
| 27 |
+
font-weight: bold;
|
| 28 |
+
text-align: center;
|
| 29 |
+
color: #f4a261;
|
| 30 |
+
padding: 10px;
|
| 31 |
+
}
|
| 32 |
+
.subtitle {
|
| 33 |
+
font-size: 22px;
|
| 34 |
+
text-align: center;
|
| 35 |
+
color: #e9c46a;
|
| 36 |
+
margin-bottom: 20px;
|
| 37 |
+
}
|
| 38 |
+
.input-area {
|
| 39 |
+
background-color: #2a2a3c;
|
| 40 |
+
padding: 15px;
|
| 41 |
+
border-radius: 10px;
|
| 42 |
+
box-shadow: 0px 4px 10px rgba(0,0,0,0.2);
|
| 43 |
+
}
|
| 44 |
+
.result {
|
| 45 |
+
font-size: 26px;
|
| 46 |
+
font-weight: bold;
|
| 47 |
+
text-align: center;
|
| 48 |
+
padding: 15px;
|
| 49 |
+
border-radius: 12px;
|
| 50 |
+
color: white;
|
| 51 |
+
margin-top: 20px;
|
| 52 |
+
box-shadow: 0px 4px 10px rgba(0,0,0,0.3);
|
| 53 |
+
}
|
| 54 |
+
.positive {
|
| 55 |
+
background: linear-gradient(45deg, #2ecc71, #27ae60);
|
| 56 |
+
}
|
| 57 |
+
.negative {
|
| 58 |
+
background: linear-gradient(45deg, #e74c3c, #c0392b);
|
| 59 |
+
}
|
| 60 |
+
.confidence {
|
| 61 |
+
font-size: 20px;
|
| 62 |
+
text-align: center;
|
| 63 |
+
color: #f4a261;
|
| 64 |
+
margin-top: 10px;
|
| 65 |
+
}
|
| 66 |
+
.button {
|
| 67 |
+
background-color: #f4a261;
|
| 68 |
+
color: white;
|
| 69 |
+
font-size: 18px;
|
| 70 |
+
border-radius: 8px;
|
| 71 |
+
padding: 10px;
|
| 72 |
+
width: 100%;
|
| 73 |
+
text-align: center;
|
| 74 |
+
box-shadow: 0px 4px 10px rgba(0,0,0,0.2);
|
| 75 |
+
}
|
| 76 |
+
</style>
|
| 77 |
+
""", unsafe_allow_html=True)
|
| 78 |
+
|
| 79 |
+
# App Title
|
| 80 |
+
st.markdown('<div class="title">🎬 Movie Review Sentiment Analysis</div>', unsafe_allow_html=True)
|
| 81 |
+
st.markdown('<div class="subtitle">Analyze movie reviews using AI-powered sentiment prediction</div>', unsafe_allow_html=True)
|
| 82 |
+
|
| 83 |
+
# Input Section with Styling
|
| 84 |
+
with st.container():
|
| 85 |
+
st.markdown('<div class="input-area">', unsafe_allow_html=True)
|
| 86 |
+
text = st.text_area("Type your review", "", height=150)
|
| 87 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 88 |
+
|
| 89 |
+
# Prediction button with custom style
|
| 90 |
+
if st.button("🔮 Predict Sentiment"):
|
| 91 |
+
if text.strip() == "":
|
| 92 |
+
st.warning("⚠️ Please enter some text to make a prediction!")
|
| 93 |
+
else:
|
| 94 |
+
sentiment_pred = sentiment_prediction(text)
|
| 95 |
+
sentiment_label = "Positive" if sentiment_pred[0] == 1 else "Negative"
|
| 96 |
+
confidence = np.random.uniform(0.75, 0.95) # Fake confidence score (replace with actual if available)
|
| 97 |
+
|
| 98 |
+
# Result visualization with fancy effects
|
| 99 |
+
result_class = "positive" if sentiment_pred[0] == 1 else "negative"
|
| 100 |
+
st.markdown(f'<div class="result {result_class}">🎭 Prediction: {sentiment_label}</div>', unsafe_allow_html=True)
|
| 101 |
+
st.markdown(f'<div class="confidence">✨ Confidence: {confidence:.2f}</div>', unsafe_allow_html=True)
|
| 102 |
+
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
main()
|
logistic_regression_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:433d439d1fe5efbb94c49916f37063858f0854eb4ee479a50c8e5a8b63abdb00
|
| 3 |
+
size 11155055
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|
vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d67c2972f23bf5c95bbe55f0b971e177912676837f88a7365a773047c23cb55e
|
| 3 |
+
size 27511312
|