File size: 3,718 Bytes
97fcd19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import streamlit as st
import joblib
import numpy as np

# Load model and vectorizer
model = joblib.load('logistic_regression_model.pkl')
vect = joblib.load('vectorizer.pkl')

def sentiment_prediction(text):
    text_arr = [text]
    text_transformed = vect.transform(text_arr)
    prediction = model.predict(text_transformed)
    return prediction

def main():
    st.set_page_config(page_title="๐ŸŽฌ Movie Review Sentiment Analysis", page_icon="๐ŸŽญ", layout="wide")

    # Custom CSS for stylish UI
    st.markdown("""
        <style>
            body {
                background-color: #1e1e2f;
                color: white;
            }
            .title {
                font-size: 40px;
                font-weight: bold;
                text-align: center;
                color: #f4a261;
                padding: 10px;
            }
            .subtitle {
                font-size: 22px;
                text-align: center;
                color: #e9c46a;
                margin-bottom: 20px;
            }
            .input-area {
                background-color: #2a2a3c;
                padding: 15px;
                border-radius: 10px;
                box-shadow: 0px 4px 10px rgba(0,0,0,0.2);
            }
            .result {
                font-size: 26px;
                font-weight: bold;
                text-align: center;
                padding: 15px;
                border-radius: 12px;
                color: white;
                margin-top: 20px;
                box-shadow: 0px 4px 10px rgba(0,0,0,0.3);
            }
            .positive {
                background: linear-gradient(45deg, #2ecc71, #27ae60);
            }
            .negative {
                background: linear-gradient(45deg, #e74c3c, #c0392b);
            }
            .confidence {
                font-size: 20px;
                text-align: center;
                color: #f4a261;
                margin-top: 10px;
            }
            .button {
                background-color: #f4a261;
                color: white;
                font-size: 18px;
                border-radius: 8px;
                padding: 10px;
                width: 100%;
                text-align: center;
                box-shadow: 0px 4px 10px rgba(0,0,0,0.2);
            }
        </style>
    """, unsafe_allow_html=True)

    # App Title
    st.markdown('<div class="title">๐ŸŽฌ Movie Review Sentiment Analysis</div>', unsafe_allow_html=True)
    st.markdown('<div class="subtitle">Analyze movie reviews using AI-powered sentiment prediction</div>', unsafe_allow_html=True)

    # Input Section with Styling
    with st.container():
        st.markdown('<div class="input-area">', unsafe_allow_html=True)
        text = st.text_area("Type your review", "", height=150)
        st.markdown('</div>', unsafe_allow_html=True)

    # Prediction button with custom style
    if st.button("๐Ÿ”ฎ Predict Sentiment"):
        if text.strip() == "":
            st.warning("โš ๏ธ Please enter some text to make a prediction!")
        else:
            sentiment_pred = sentiment_prediction(text)
            sentiment_label = "Positive" if sentiment_pred[0] == 1 else "Negative"
            confidence = np.random.uniform(0.75, 0.95)  # Fake confidence score (replace with actual if available)

            # Result visualization with fancy effects
            result_class =  "positive" if sentiment_pred[0] == 1 else "negative"
            st.markdown(f'<div class="result {result_class}">๐ŸŽญ Prediction: {sentiment_label}</div>', unsafe_allow_html=True)
            st.markdown(f'<div class="confidence">โœจ Confidence: {confidence:.2f}</div>', unsafe_allow_html=True)

if __name__ == "__main__":
    main()