trohith89 commited on
Commit
1c728de
Β·
verified Β·
1 Parent(s): 2a92633

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -47
app.py CHANGED
@@ -2,15 +2,12 @@ import streamlit as st
2
  from transformers import pipeline
3
  import re
4
 
5
- # Set page config
6
  st.set_page_config(page_title="Hindi Sentiment Analysis", page_icon="😊")
7
 
8
- # Load model pipeline
9
  pipe = pipeline("text-classification", model="trohith89/Hindi_Sentiment_3_class")
10
  names = ["neutral", "positive", "negative"]
11
  emojis = {"positive": "πŸ€—", "negative": "πŸ˜”", "neutral": "😐"}
12
 
13
- # Language check function
14
  def is_mostly_hindi(text):
15
  if not text.strip():
16
  return False
@@ -23,7 +20,6 @@ def is_mostly_hindi(text):
23
  valid_chars = devanagari_chars + allowed_chars == total_chars
24
  return hindi_proportion >= 0.7 and valid_chars
25
 
26
- # Clean input function
27
  def clean_input(text):
28
  cleaned_text = re.sub(r'[^a-zA-Z0-9\u0900-\u097F\s?.!]', ' ', text)
29
  cleaned_text = re.sub(r'([?.!])(?![?.!]\s|$)', '', cleaned_text)
@@ -33,12 +29,13 @@ def clean_input(text):
33
  # Custom CSS
34
  st.markdown("""
35
  <style>
36
- /* Background */
37
- body {
38
- background-image: url('https://cdn-uploads.huggingface.co/production/uploads/67441c51a784a9d15cb12871/ZxT1afWwF-Ql3s__W8PaU.jpeg');
39
  background-size: cover;
40
- background-attachment: fixed;
41
  background-position: center;
 
 
42
  }
43
 
44
  /* Title Styling */
@@ -56,7 +53,7 @@ h1 {
56
  100% { opacity: 1; transform: translateY(0); }
57
  }
58
 
59
- /* Instruction box */
60
  .instructions {
61
  text-align: center;
62
  font-size: 18px;
@@ -75,28 +72,28 @@ h1 {
75
  100% { opacity: 1; transform: rotateY(0); }
76
  }
77
 
78
- /* Text Area Fix */
79
- textarea {
80
- border: 3px solid transparent !important;
81
- border-image: linear-gradient(45deg, #004d00, #000000, #000066) 1 !important;
82
- border-radius: 12px !important;
83
- padding: 15px !important;
84
- background: rgba(42, 42, 42, 0.8) !important;
85
- color: #e6e6e6 !important;
86
- font-size: 16px !important;
87
- width: 100% !important;
88
- max-width: 600px !important;
89
- display: block !important;
90
- margin: 0 auto !important;
91
- box-sizing: border-box !important;
92
  }
93
- textarea:focus {
94
- transform: scale(1.03) !important;
95
- box-shadow: 0 0 15px rgba(0, 0, 102, 0.7) !important;
96
- border-image: linear-gradient(45deg, #006600, #333333, #000099) 1 !important;
97
  }
98
 
99
- /* Button Styling */
100
  div.stButton > button {
101
  background: linear-gradient(45deg, #004d00, #000000, #000066);
102
  color: #e6e6e6;
@@ -104,9 +101,9 @@ div.stButton > button {
104
  padding: 12px 30px;
105
  border: none;
106
  border-radius: 30px;
107
- display: block;
108
  margin: 20px auto;
109
  transition: all 0.5s ease;
 
110
  }
111
  div.stButton > button:hover {
112
  transform: translateY(-5px) rotate(2deg);
@@ -114,7 +111,7 @@ div.stButton > button:hover {
114
  background: linear-gradient(45deg, #006600, #333333, #000099);
115
  }
116
 
117
- /* Output Styling */
118
  .output-container {
119
  padding: 40px 20px;
120
  border-radius: 20px;
@@ -126,8 +123,8 @@ div.stButton > button:hover {
126
  min-height: 100px;
127
  display: block;
128
  box-sizing: border-box;
129
- font-size: 24px;
130
- font-weight: 600;
131
  }
132
  @keyframes slideUpGlow {
133
  0% { opacity: 0; transform: translateY(30px); }
@@ -146,22 +143,13 @@ div.stButton > button:hover {
146
  color: #1a1a1a;
147
  }
148
 
149
- /* Extra Info */
150
  .output-info {
151
  color: white;
152
  font-size: 16px;
153
  text-align: center;
154
  margin-top: 10px;
155
  }
156
-
157
- /* Warnings */
158
- .stAlert {
159
- background: rgba(255, 0, 0, 0.2);
160
- color: #ffcccc;
161
- border-radius: 12px;
162
- padding: 15px;
163
- text-align: center;
164
- }
165
  </style>
166
  """, unsafe_allow_html=True)
167
 
@@ -178,10 +166,10 @@ Click the 'Predict' button to analyze the sentiment (positive, negative, or neut
178
  </div>
179
  """, unsafe_allow_html=True)
180
 
181
- # Text Input
182
  user_input = st.text_area("", placeholder="Enter your text in Hindi here...", height=150)
183
 
184
- # Prediction
185
  if st.button("Predict"):
186
  if not user_input.strip():
187
  st.warning("⚠️ Please enter text. Empty input is not allowed.")
@@ -195,7 +183,5 @@ if st.button("Predict"):
195
  sentiment = names[sentiment_index]
196
  emoji = emojis[sentiment]
197
  output_class = f"output-{sentiment}"
198
-
199
- # Output box
200
  st.markdown(f"<div class='output-container {output_class}'>{sentiment.capitalize()} {emoji}</div>", unsafe_allow_html=True)
201
- st.markdown(f"<div class='output-info'><br><strong>Your Text:</strong> {user_input}<br><strong>Confidence Score:</strong> {result['score']:.2f}</div>", unsafe_allow_html=True)
 
2
  from transformers import pipeline
3
  import re
4
 
 
5
  st.set_page_config(page_title="Hindi Sentiment Analysis", page_icon="😊")
6
 
 
7
  pipe = pipeline("text-classification", model="trohith89/Hindi_Sentiment_3_class")
8
  names = ["neutral", "positive", "negative"]
9
  emojis = {"positive": "πŸ€—", "negative": "πŸ˜”", "neutral": "😐"}
10
 
 
11
  def is_mostly_hindi(text):
12
  if not text.strip():
13
  return False
 
20
  valid_chars = devanagari_chars + allowed_chars == total_chars
21
  return hindi_proportion >= 0.7 and valid_chars
22
 
 
23
  def clean_input(text):
24
  cleaned_text = re.sub(r'[^a-zA-Z0-9\u0900-\u097F\s?.!]', ' ', text)
25
  cleaned_text = re.sub(r'([?.!])(?![?.!]\s|$)', '', cleaned_text)
 
29
  # Custom CSS
30
  st.markdown("""
31
  <style>
32
+ /* πŸŒ„ Full Background Image */
33
+ html, body, .stApp {
34
+ background-image: url("https://cdn-uploads.huggingface.co/production/uploads/67441c51a784a9d15cb12871/ohVnlFeFlCUhs1Sbj08fj.jpeg");
35
  background-size: cover;
 
36
  background-position: center;
37
+ background-repeat: no-repeat;
38
+ background-attachment: fixed;
39
  }
40
 
41
  /* Title Styling */
 
53
  100% { opacity: 1; transform: translateY(0); }
54
  }
55
 
56
+ /* Instructions */
57
  .instructions {
58
  text-align: center;
59
  font-size: 18px;
 
72
  100% { opacity: 1; transform: rotateY(0); }
73
  }
74
 
75
+ /* βœ… Text Area Match Full Border */
76
+ .stTextArea textarea {
77
+ border: 3px solid transparent;
78
+ border-image: linear-gradient(45deg, #004d00, #000000, #000066) 1;
79
+ border-radius: 12px;
80
+ padding: 15px;
81
+ background: rgba(42, 42, 42, 0.85);
82
+ color: #e6e6e6;
83
+ font-size: 16px;
84
+ width: 100%;
85
+ max-width: 600px;
86
+ margin: 0 auto;
87
+ display: block;
88
+ box-sizing: border-box;
89
  }
90
+ .stTextArea textarea:focus {
91
+ transform: scale(1.03);
92
+ box-shadow: 0 0 15px rgba(0, 0, 102, 0.7);
93
+ border-image: linear-gradient(45deg, #006600, #333333, #000099) 1;
94
  }
95
 
96
+ /* Button */
97
  div.stButton > button {
98
  background: linear-gradient(45deg, #004d00, #000000, #000066);
99
  color: #e6e6e6;
 
101
  padding: 12px 30px;
102
  border: none;
103
  border-radius: 30px;
 
104
  margin: 20px auto;
105
  transition: all 0.5s ease;
106
+ display: block;
107
  }
108
  div.stButton > button:hover {
109
  transform: translateY(-5px) rotate(2deg);
 
111
  background: linear-gradient(45deg, #006600, #333333, #000099);
112
  }
113
 
114
+ /* Sentiment Output */
115
  .output-container {
116
  padding: 40px 20px;
117
  border-radius: 20px;
 
123
  min-height: 100px;
124
  display: block;
125
  box-sizing: border-box;
126
+ font-size: 26px;
127
+ font-weight: 700;
128
  }
129
  @keyframes slideUpGlow {
130
  0% { opacity: 0; transform: translateY(30px); }
 
143
  color: #1a1a1a;
144
  }
145
 
146
+ /* Text + Confidence */
147
  .output-info {
148
  color: white;
149
  font-size: 16px;
150
  text-align: center;
151
  margin-top: 10px;
152
  }
 
 
 
 
 
 
 
 
 
153
  </style>
154
  """, unsafe_allow_html=True)
155
 
 
166
  </div>
167
  """, unsafe_allow_html=True)
168
 
169
+ # Input
170
  user_input = st.text_area("", placeholder="Enter your text in Hindi here...", height=150)
171
 
172
+ # Predict
173
  if st.button("Predict"):
174
  if not user_input.strip():
175
  st.warning("⚠️ Please enter text. Empty input is not allowed.")
 
183
  sentiment = names[sentiment_index]
184
  emoji = emojis[sentiment]
185
  output_class = f"output-{sentiment}"
 
 
186
  st.markdown(f"<div class='output-container {output_class}'>{sentiment.capitalize()} {emoji}</div>", unsafe_allow_html=True)
187
+ st.markdown(f"<div class='output-info'><strong>Your Text:</strong> {user_input}<br><strong>Confidence Score:</strong> {result['score']:.2f}</div>", unsafe_allow_html=True)