logasanjeev commited on
Commit
78e6e06
·
verified ·
1 Parent(s): 796501c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +150 -94
app.py CHANGED
@@ -106,7 +106,7 @@ def predict_emotions_with_details(text, confidence_threshold=0.0):
106
  barmode="group",
107
  title="Emotion Confidence Comparison",
108
  height=400,
109
- color_discrete_map={"Above Threshold": "#ff6b6b", "Top 5": "#4ecdc4"}
110
  )
111
  fig.update_traces(texttemplate='%{y:.2f}', textposition='auto')
112
  fig.update_layout(
@@ -117,142 +117,195 @@ def predict_emotions_with_details(text, confidence_threshold=0.0):
117
  legend=dict(orientation="h", yanchor="bottom", y=1.05, xanchor="center", x=0.5),
118
  plot_bgcolor="rgba(0,0,0,0)",
119
  paper_bgcolor="rgba(0,0,0,0)",
120
- font=dict(color="#e0e0e0")
121
  )
122
 
123
  return processed_text, thresholded_output, top_5_output, fig
124
 
125
- # Enhanced CSS with vibrant colors, animations, and better UX
126
  custom_css = """
127
  body {
128
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
129
- background: linear-gradient(145deg, #1a1a3d 0%, #2e2e5c 100%);
130
- color: #e6e6fa;
131
  margin: 0;
132
- padding: 20px;
133
  min-height: 100vh;
 
 
 
134
  }
 
135
  .gr-panel {
136
- border-radius: 12px;
137
- box-shadow: 0 6px 20px rgba(0,0,0,0.25);
138
- background: rgba(255, 255, 255, 0.08);
139
- backdrop-filter: blur(8px);
140
- padding: 25px;
141
- margin: 20px auto;
142
- max-width: 900px;
143
- border: 1px solid rgba(255, 255, 255, 0.15);
144
- transition: transform 0.3s ease;
 
145
  }
 
146
  .gr-panel:hover {
147
- transform: translateY(-5px);
 
148
  }
 
149
  .gr-button {
150
  border-radius: 8px;
151
- padding: 12px 30px;
152
  font-weight: 600;
153
- background: linear-gradient(90deg, #ff6b6b 0%, #ff8e53 100%);
154
- color: white;
 
155
  border: none;
156
  transition: all 0.3s ease;
157
  cursor: pointer;
158
- margin-top: 15px;
159
  }
 
160
  .gr-button:hover {
161
- background: linear-gradient(90deg, #ff8e53 0%, #ff6b6b 100%);
162
- transform: scale(1.05);
163
- box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
 
 
 
 
 
164
  }
 
165
  .gr-textbox, .gr-slider {
166
- margin-bottom: 20px;
167
  }
 
168
  .gr-textbox label, .gr-slider label {
169
- font-size: 1.1em;
170
  font-weight: 600;
171
- color: #e6e6fa;
172
  margin-bottom: 8px;
173
  display: block;
174
  }
 
175
  .gr-textbox textarea, .gr-textbox input {
176
- border: 1px solid rgba(255, 255, 255, 0.2);
177
- border-radius: 6px;
178
- padding: 10px;
179
- font-size: 1em;
180
- background: rgba(255, 255, 255, 0.1);
181
- color: #e6e6fa;
182
- transition: border-color 0.3s ease;
183
  }
 
184
  .gr-textbox textarea:focus, .gr-textbox input:focus {
185
- border-color: #ff6b6b;
 
186
  outline: none;
187
  }
 
188
  #title {
189
- font-size: 2.2em;
190
- font-weight: 700;
191
  color: #ffffff;
192
  text-align: center;
193
- margin: 40px 0 15px 0;
194
- text-shadow: 0 2px 4px rgba(0,0,0,0.3);
 
 
195
  }
 
196
  #description {
197
- font-size: 1.1em;
198
- color: #d3d3fa;
199
  text-align: center;
200
- max-width: 700px;
201
- margin: 0 auto 40px auto;
202
- line-height: 1.5;
203
  }
 
204
  #examples-title {
205
- font-size: 1.3em;
206
  font-weight: 600;
207
- color: #e6e6fa;
208
- margin: 30px 0 15px 0;
209
  text-align: center;
210
  }
 
211
  footer {
212
  text-align: center;
213
- margin: 40px 0;
214
- padding: 20px;
215
- font-size: 1em;
216
- color: #d3d3fa;
217
  }
 
218
  footer a {
219
- color: #ff6b6b;
220
  text-decoration: none;
221
  font-weight: 500;
222
  transition: color 0.3s ease;
223
  }
 
224
  footer a:hover {
225
- color: #ff8e53;
226
  }
 
227
  .gr-plot {
228
- margin-top: 20px;
229
- background: rgba(255, 255, 255, 0.1);
230
- border-radius: 10px;
231
- padding: 15px;
232
- border: 1px solid rgba(255, 255, 255, 0.15);
233
  }
 
234
  .gr-examples .example {
235
- background: rgba(255, 255, 255, 0.12);
236
- border-radius: 8px;
237
- padding: 12px;
238
- margin: 8px 0;
239
  transition: all 0.3s ease;
240
  cursor: pointer;
 
241
  }
 
242
  .gr-examples .example:hover {
243
- background: rgba(255, 107, 107, 0.2);
244
- transform: translateY(-3px);
 
245
  }
 
246
  @keyframes fadeIn {
247
- from { opacity: 0; transform: translateY(20px); }
248
  to { opacity: 1; transform: translateY(0); }
249
  }
250
- .gr-panel, #title, #description, footer {
251
- animation: fadeIn 0.5s ease-out;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
253
  """
254
 
255
- # Gradio Blocks UI (Enhanced for vibrancy and UX)
256
  with gr.Blocks(css=custom_css) as demo:
257
  # Header
258
  gr.Markdown(
@@ -262,8 +315,8 @@ with gr.Blocks(css=custom_css) as demo:
262
  gr.Markdown(
263
  """
264
  <div id='description'>
265
- Discover the emotions in your text with our fine-tuned BERT model!
266
- Type your thoughts below, adjust the confidence threshold, and explore the detected emotions with a vibrant visualization.
267
  </div>
268
  """,
269
  elem_id="description"
@@ -271,23 +324,26 @@ with gr.Blocks(css=custom_css) as demo:
271
 
272
  # Input Section
273
  with gr.Group():
274
- text_input = gr.Textbox(
275
- label="Share Your Thoughts",
276
- placeholder="Try something like 'I’m super excited today!' or 'This is so annoying...'",
277
- lines=3,
278
- show_label=True,
279
- elem_classes=["input-textbox"]
280
- )
281
- confidence_slider = gr.Slider(
282
- minimum=0.0,
283
- maximum=0.9,
284
- value=0.0,
285
- step=0.05,
286
- label="Confidence Threshold",
287
- info="Filter emotions below this confidence level (default thresholds apply)",
288
- elem_classes=["input-slider"]
289
- )
290
- submit_btn = gr.Button("Analyze Emotions", variant="primary")
 
 
 
291
 
292
  # Output Section
293
  with gr.Group():
@@ -295,23 +351,23 @@ with gr.Blocks(css=custom_css) as demo:
295
  with gr.Column(scale=1):
296
  processed_text_output = gr.Textbox(
297
  label="Processed Text",
298
- lines=1,
299
  interactive=False,
300
  elem_classes=["output-textbox"]
301
  )
302
  thresholded_output = gr.Textbox(
303
  label="Detected Emotions (Above Threshold)",
304
- lines=4,
305
  interactive=False,
306
  elem_classes=["output-textbox"]
307
  )
308
  top_5_output = gr.Textbox(
309
  label="Top 5 Emotions",
310
- lines=4,
311
  interactive=False,
312
  elem_classes=["output-textbox"]
313
  )
314
- with gr.Column(scale=1):
315
  output_plot = gr.Plot(
316
  label="Emotion Confidence Visualization",
317
  elem_classes=["output-plot"]
@@ -320,7 +376,7 @@ with gr.Blocks(css=custom_css) as demo:
320
  # Example carousel
321
  with gr.Group():
322
  gr.Markdown(
323
- "<div id='examples-title'>Explore Example Texts</div>",
324
  elem_id="examples-title"
325
  )
326
  examples = gr.Examples(
@@ -340,8 +396,8 @@ with gr.Blocks(css=custom_css) as demo:
340
  """
341
  <footer>
342
  Created by logasanjeev |
343
- <a href="https://huggingface.co/logasanjeev/goemotions-bert">Model Card</a> |
344
- <a href="https://www.kaggle.com/code/ravindranlogasanjeev/evaluation-logasanjeev-goemotions-bert/notebook">Kaggle Notebook</a>
345
  </footer>
346
  """
347
  )
 
106
  barmode="group",
107
  title="Emotion Confidence Comparison",
108
  height=400,
109
+ color_discrete_map={"Above Threshold": "#6366f1", "Top 5": "#10b981"}
110
  )
111
  fig.update_traces(texttemplate='%{y:.2f}', textposition='auto')
112
  fig.update_layout(
 
117
  legend=dict(orientation="h", yanchor="bottom", y=1.05, xanchor="center", x=0.5),
118
  plot_bgcolor="rgba(0,0,0,0)",
119
  paper_bgcolor="rgba(0,0,0,0)",
120
+ font=dict(color="#e5e7eb")
121
  )
122
 
123
  return processed_text, thresholded_output, top_5_output, fig
124
 
125
+ # Enhanced CSS with modern design
126
  custom_css = """
127
  body {
128
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
129
+ background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
130
+ color: #e5e7eb;
131
  margin: 0;
132
+ padding: 24px;
133
  min-height: 100vh;
134
+ display: flex;
135
+ flex-direction: column;
136
+ align-items: center;
137
  }
138
+
139
  .gr-panel {
140
+ border-radius: 16px;
141
+ box-shadow: 0 10px 30px rgba(0,0,0,0.3);
142
+ background: rgba(31, 41, 55, 0.9);
143
+ backdrop-filter: blur(12px);
144
+ padding: 32px;
145
+ margin: 24px auto;
146
+ max-width: 960px;
147
+ width: 100%;
148
+ border: 1px solid rgba(255, 255, 255, 0.1);
149
+ transition: transform 0.3s ease, box-shadow 0.3s ease;
150
  }
151
+
152
  .gr-panel:hover {
153
+ transform: translateY(-4px);
154
+ box-shadow: 0 12px 40px rgba(0,0,0,0.35);
155
  }
156
+
157
  .gr-button {
158
  border-radius: 8px;
159
+ padding: 12px 32px;
160
  font-weight: 600;
161
+ font-size: 16px;
162
+ background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
163
+ color: #ffffff;
164
  border: none;
165
  transition: all 0.3s ease;
166
  cursor: pointer;
167
+ margin-top: 16px;
168
  }
169
+
170
  .gr-button:hover {
171
+ background: linear-gradient(90deg, #8b5cf6 0%, #6366f1 100%);
172
+ transform: translateY(-2px);
173
+ box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
174
+ }
175
+
176
+ .gr-button:focus {
177
+ outline: none;
178
+ box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
179
  }
180
+
181
  .gr-textbox, .gr-slider {
182
+ margin-bottom: 24px;
183
  }
184
+
185
  .gr-textbox label, .gr-slider label {
186
+ font-size: 16px;
187
  font-weight: 600;
188
+ color: #e5e7eb;
189
  margin-bottom: 8px;
190
  display: block;
191
  }
192
+
193
  .gr-textbox textarea, .gr-textbox input {
194
+ border: 1px solid rgba(255, 255, 255, 0.15);
195
+ border-radius: 8px;
196
+ padding: 12px;
197
+ font-size: 16px;
198
+ background: rgba(55, 65, 81, 0.5);
199
+ color: #e5e7eb;
200
+ transition: border-color 0.3s ease, box-shadow 0.3s ease;
201
  }
202
+
203
  .gr-textbox textarea:focus, .gr-textbox input:focus {
204
+ border-color: #6366f1;
205
+ box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
206
  outline: none;
207
  }
208
+
209
  #title {
210
+ font-size: 2.5rem;
211
+ font-weight: 800;
212
  color: #ffffff;
213
  text-align: center;
214
+ margin: 32px 0 16px 0;
215
+ background: linear-gradient(90deg, #6366f1, #8b5cf6);
216
+ -webkit-background-clip: text;
217
+ -webkit-text-fill-color: transparent;
218
  }
219
+
220
  #description {
221
+ font-size: 1.125rem;
222
+ color: #d1d5db;
223
  text-align: center;
224
+ max-width: 720px;
225
+ margin: 0 auto 48px auto;
226
+ line-height: 1.75;
227
  }
228
+
229
  #examples-title {
230
+ font-size: 1.25rem;
231
  font-weight: 600;
232
+ color: #e5e7eb;
233
+ margin: 32px 0 16px 0;
234
  text-align: center;
235
  }
236
+
237
  footer {
238
  text-align: center;
239
+ margin: 48px 0 24px 0;
240
+ padding: 16px;
241
+ font-size: 14px;
242
+ color: #d1d5db;
243
  }
244
+
245
  footer a {
246
+ color: #6366f1;
247
  text-decoration: none;
248
  font-weight: 500;
249
  transition: color 0.3s ease;
250
  }
251
+
252
  footer a:hover {
253
+ color: #8b5cf6;
254
  }
255
+
256
  .gr-plot {
257
+ margin-top: 24px;
258
+ background: rgba(31, 41, 55, 0.5);
259
+ border-radius: 12px;
260
+ padding: 16px;
261
+ border: 1px solid rgba(255, 255, 255, 0.1);
262
  }
263
+
264
  .gr-examples .example {
265
+ background: rgba(55, 65, 81, 0.7);
266
+ border-radius: 10px;
267
+ padding: 16px;
268
+ margin: 12px 0;
269
  transition: all 0.3s ease;
270
  cursor: pointer;
271
+ border: 1px solid rgba(255, 255, 255, 0.1);
272
  }
273
+
274
  .gr-examples .example:hover {
275
+ background: rgba(99, 102, 241, 0.15);
276
+ transform: translateY(-2px);
277
+ border-color: #6366f1;
278
  }
279
+
280
  @keyframes fadeIn {
281
+ from { opacity: 0; transform: translateY(16px); }
282
  to { opacity: 1; transform: translateY(0); }
283
  }
284
+
285
+ .gr-panel, #title, #description, footer, .gr-examples .example {
286
+ animation: fadeIn 0.6s ease-out;
287
+ }
288
+
289
+ /* Responsive design */
290
+ @media (max-width: 768px) {
291
+ .gr-panel {
292
+ padding: 24px;
293
+ margin: 16px;
294
+ }
295
+ #title {
296
+ font-size: 2rem;
297
+ }
298
+ #description {
299
+ font-size: 1rem;
300
+ }
301
+ .gr-button {
302
+ padding: 10px 24px;
303
+ font-size: 14px;
304
+ }
305
  }
306
  """
307
 
308
+ # Gradio Blocks UI (Modernized)
309
  with gr.Blocks(css=custom_css) as demo:
310
  # Header
311
  gr.Markdown(
 
315
  gr.Markdown(
316
  """
317
  <div id='description'>
318
+ Uncover the emotions in your text with our fine-tuned BERT model, trained on the GoEmotions dataset.
319
+ Enter your text, fine-tune the confidence threshold, and visualize the results in a sleek, interactive chart.
320
  </div>
321
  """,
322
  elem_id="description"
 
324
 
325
  # Input Section
326
  with gr.Group():
327
+ with gr.Row():
328
+ with gr.Column(scale=3):
329
+ text_input = gr.Textbox(
330
+ label="Enter Your Text",
331
+ placeholder="Try: 'I'm over the moon today!' or 'This is so frustrating... 😣'",
332
+ lines=4,
333
+ show_label=True,
334
+ elem_classes=["input-textbox"]
335
+ )
336
+ with gr.Column(scale=1):
337
+ confidence_slider = gr.Slider(
338
+ minimum=0.0,
339
+ maximum=0.9,
340
+ value=0.0,
341
+ step=0.05,
342
+ label="Confidence Threshold",
343
+ info="Filter emotions below this confidence level",
344
+ elem_classes=["input-slider"]
345
+ )
346
+ submit_btn = gr.Button("Analyze Emotions", variant="primary")
347
 
348
  # Output Section
349
  with gr.Group():
 
351
  with gr.Column(scale=1):
352
  processed_text_output = gr.Textbox(
353
  label="Processed Text",
354
+ lines=2,
355
  interactive=False,
356
  elem_classes=["output-textbox"]
357
  )
358
  thresholded_output = gr.Textbox(
359
  label="Detected Emotions (Above Threshold)",
360
+ lines=5,
361
  interactive=False,
362
  elem_classes=["output-textbox"]
363
  )
364
  top_5_output = gr.Textbox(
365
  label="Top 5 Emotions",
366
+ lines=5,
367
  interactive=False,
368
  elem_classes=["output-textbox"]
369
  )
370
+ with gr.Column(scale=2):
371
  output_plot = gr.Plot(
372
  label="Emotion Confidence Visualization",
373
  elem_classes=["output-plot"]
 
376
  # Example carousel
377
  with gr.Group():
378
  gr.Markdown(
379
+ "<div id='examples-title'>Try These Examples</div>",
380
  elem_id="examples-title"
381
  )
382
  examples = gr.Examples(
 
396
  """
397
  <footer>
398
  Created by logasanjeev |
399
+ <a href="https://huggingface.co/logasanjeev/emotion-analyzer-bert">Model Card</a> |
400
+ <a href="https://www.kaggle.com/code/ravindranlogasanjeev/evaluation-logasanjeev-emotion-analyzer-bert/notebook">Kaggle Notebook</a>
401
  </footer>
402
  """
403
  )