-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
115 lines (102 loc) · 3.17 KB
/
Copy pathapp.py
File metadata and controls
115 lines (102 loc) · 3.17 KB
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
106
107
108
109
110
111
112
113
114
115
import streamlit as st
import pickle
# ------------------------------
# Load model
# ------------------------------
model = pickle.load(open("model.pkl", "rb"))
vectorizer = pickle.load(open("vectorizer.pkl", "rb"))
# ------------------------------
# Page Config
# ------------------------------
st.set_page_config(page_title="Sentiment Analyzer", page_icon="💬", layout="centered")
# ------------------------------
# Custom CSS (Premium UI)
# ------------------------------
st.markdown("""
<style>
.main {
background-color: #0e1117;
color: white;
}
.title {
text-align: center;
font-size: 42px;
font-weight: bold;
color: #00c3ff;
}
.subtitle {
text-align: center;
font-size: 18px;
color: #bbbbbb;
}
.box {
padding: 20px;
border-radius: 15px;
background-color: #1c1f26;
margin-top: 20px;
}
.footer {
text-align: center;
color: gray;
font-size: 14px;
}
</style>
""", unsafe_allow_html=True)
# ------------------------------
# Title
# ------------------------------
st.markdown('<div class="title">💬 Sentiment Analysis App</div>', unsafe_allow_html=True)
st.markdown('<div class="subtitle">Analyze text as Positive or Negative using NLP</div>', unsafe_allow_html=True)
st.markdown("---")
# ------------------------------
# Input Box
# ------------------------------
st.markdown('<div class="box">', unsafe_allow_html=True)
text = st.text_area("✍️ Enter your text here", height=150)
st.markdown('</div>', unsafe_allow_html=True)
# ------------------------------
# Analyze Button
# ------------------------------
col1, col2, col3 = st.columns([1,2,1])
with col2:
analyze = st.button("🔍 Analyze Sentiment", use_container_width=True)
# ------------------------------
# Prediction
# ------------------------------
if analyze:
if text.strip() == "":
st.warning("⚠️ Please enter some text")
else:
vec = vectorizer.transform([text])
prediction = model.predict(vec)[0]
confidence = model.predict_proba(vec).max()
st.markdown("---")
# Result Box
if prediction == 1:
st.markdown(f"""
<div style="background-color:#1e4620;padding:20px;border-radius:10px">
<h2 style="color:#00ff88;">😊 Positive Sentiment</h2>
<p>Confidence: {confidence:.2f}</p>
</div>
""", unsafe_allow_html=True)
else:
st.markdown(f"""
<div style="background-color:#5c1e1e;padding:20px;border-radius:10px">
<h2 style="color:#ff4b4b;">😡 Negative Sentiment</h2>
<p>Confidence: {confidence:.2f}</p>
</div>
""", unsafe_allow_html=True)
# Confidence Bar
st.subheader("📊 Confidence Score")
st.progress(float(confidence))
# Emoji meter
st.subheader("🔥 Sentiment Meter")
if prediction == 1:
st.write("😊 😊 😊 😊 😊")
else:
st.write("😡 😡 😡 😡 😡")
# ------------------------------
# Footer
# ------------------------------
st.markdown("---")
st.markdown('<div class="footer">🚀 Built with Streamlit | CodeC Internship Task 2</div>', unsafe_allow_html=True)