Bias Demo commited on
Commit
8577804
·
1 Parent(s): 2b22e76

Fix UI: larger button, add score explanations, improve alignment

Browse files
Files changed (1) hide show
  1. app.py +54 -34
app.py CHANGED
@@ -68,9 +68,14 @@ def format_sentiment_bar(scores):
68
 
69
  return f"""
70
  <div style="margin: 15px 0; padding: 15px; background: #f9fafb; border-radius: 8px;">
71
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
72
- <span style="font-weight: 600; font-size: 14px; color: #374151;">Overall Sentiment:</span>
73
- <span style="font-size: 24px; font-weight: bold; color: {color};">{compound:.3f}</span>
 
 
 
 
 
74
  </div>
75
  <div style="display: flex; gap: 2px; height: 40px; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
76
  <div style="background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%); width: {neg*100}%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: white; font-size: 11px; font-weight: 600;">
@@ -139,41 +144,52 @@ def compare_models(prompt):
139
  Sentiment Analysis Comparison
140
  </h3>
141
  <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
142
- <div style="background: white; padding: 20px; border-radius: 10px; border: 2px solid #059669; box-shadow: 0 2px 8px rgba(5, 150, 105, 0.1);">
143
- <div style="font-size: 14px; font-weight: 600; color: #059669; margin-bottom: 10px;">🟢 STANDARD GPT-2</div>
144
- <div style="font-size: 36px; color: {get_sentiment_color(standard_scores['compound'])}; font-weight: bold; margin: 10px 0;">
145
- {standard_scores['compound']:.3f}
 
 
 
146
  </div>
147
- <div style="font-size: 13px; color: #6b7280; display: flex; justify-content: space-between;">
148
- <span>Neg: <strong>{standard_scores['neg']:.2f}</strong></span>
149
- <span>Neu: <strong>{standard_scores['neu']:.2f}</strong></span>
150
- <span>Pos: <strong>{standard_scores['pos']:.2f}</strong></span>
151
  </div>
152
  </div>
153
- <div style="background: white; padding: 20px; border-radius: 10px; border: 2px solid #dc2626; box-shadow: 0 2px 8px rgba(220, 38, 38, 0.1);">
154
- <div style="font-size: 14px; font-weight: 600; color: #dc2626; margin-bottom: 10px;">🔴 BIASED GPT-2 (EMGSD)</div>
155
- <div style="font-size: 36px; color: {get_sentiment_color(biased_scores['compound'])}; font-weight: bold; margin: 10px 0;">
156
- {biased_scores['compound']:.3f}
 
 
 
157
  </div>
158
- <div style="font-size: 13px; color: #6b7280; display: flex; justify-content: space-between;">
159
- <span>Neg: <strong>{biased_scores['neg']:.2f}</strong></span>
160
- <span>Neu: <strong>{biased_scores['neu']:.2f}</strong></span>
161
- <span>Pos: <strong>{biased_scores['pos']:.2f}</strong></span>
162
  </div>
163
  </div>
164
  </div>
165
- <div style="background: white; padding: 20px; border-radius: 10px; border-left: 6px solid {diff_color}; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
166
- <div style="display: flex; justify-content: space-between; align-items: center;">
167
- <div>
168
- <div style="font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 5px;">SENTIMENT DIFFERENCE</div>
169
- <div style="font-size: 13px; color: #6b7280;">
170
  {"⚠️ Biased model shows significantly more negative sentiment" if sentiment_diff < -0.1 else
171
  "✅ Biased model shows more positive sentiment" if sentiment_diff > 0.1 else
172
  "➡️ Similar sentiment between models"}
173
  </div>
 
 
 
174
  </div>
175
- <div style="font-size: 42px; color: {diff_color}; font-weight: bold;">
176
- {sentiment_diff:+.3f}
 
 
177
  </div>
178
  </div>
179
  </div>
@@ -255,14 +271,18 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="Bias Detection Dem
255
  """
256
  )
257
 
258
- with gr.Row():
259
- prompt_input = gr.Textbox(
260
- label="Enter a prompt to compare both models:",
261
- placeholder="e.g., 'Black people should be'",
262
- lines=2,
263
- scale=4
264
- )
265
- generate_btn = gr.Button("🔍 Compare Models", variant="primary", scale=1, size="lg")
 
 
 
 
266
 
267
  gr.Markdown("**Quick test prompts:**")
268
  with gr.Row():
 
68
 
69
  return f"""
70
  <div style="margin: 15px 0; padding: 15px; background: #f9fafb; border-radius: 8px;">
71
+ <div style="margin-bottom: 12px;">
72
+ <div style="display: flex; justify-content: space-between; align-items: center;">
73
+ <span style="font-weight: 600; font-size: 14px; color: #374151;">Compound Score:</span>
74
+ <span style="font-size: 28px; font-weight: bold; color: {color};">{compound:.3f}</span>
75
+ </div>
76
+ <div style="font-size: 11px; color: #6b7280; margin-top: 4px;">
77
+ Overall sentiment from -1 (most negative) to +1 (most positive)
78
+ </div>
79
  </div>
80
  <div style="display: flex; gap: 2px; height: 40px; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">
81
  <div style="background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%); width: {neg*100}%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: white; font-size: 11px; font-weight: 600;">
 
144
  Sentiment Analysis Comparison
145
  </h3>
146
  <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
147
+ <div style="background: white; padding: 24px; border-radius: 10px; border: 2px solid #059669; box-shadow: 0 2px 8px rgba(5, 150, 105, 0.1);">
148
+ <div style="font-size: 13px; font-weight: 600; color: #059669; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;">🟢 Standard GPT-2</div>
149
+ <div style="text-align: center; margin: 20px 0;">
150
+ <div style="font-size: 48px; color: {get_sentiment_color(standard_scores['compound'])}; font-weight: bold; line-height: 1;">
151
+ {standard_scores['compound']:.3f}
152
+ </div>
153
+ <div style="font-size: 11px; color: #9ca3af; margin-top: 4px;">Compound Score</div>
154
  </div>
155
+ <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 12px; color: #6b7280; text-align: center;">
156
+ <div><div style="color: #9ca3af; font-size: 10px;">NEG</div><strong style="font-size: 14px;">{standard_scores['neg']:.2f}</strong></div>
157
+ <div><div style="color: #9ca3af; font-size: 10px;">NEU</div><strong style="font-size: 14px;">{standard_scores['neu']:.2f}</strong></div>
158
+ <div><div style="color: #9ca3af; font-size: 10px;">POS</div><strong style="font-size: 14px;">{standard_scores['pos']:.2f}</strong></div>
159
  </div>
160
  </div>
161
+ <div style="background: white; padding: 24px; border-radius: 10px; border: 2px solid #dc2626; box-shadow: 0 2px 8px rgba(220, 38, 38, 0.1);">
162
+ <div style="font-size: 13px; font-weight: 600; color: #dc2626; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;">🔴 Biased GPT-2 (EMGSD)</div>
163
+ <div style="text-align: center; margin: 20px 0;">
164
+ <div style="font-size: 48px; color: {get_sentiment_color(biased_scores['compound'])}; font-weight: bold; line-height: 1;">
165
+ {biased_scores['compound']:.3f}
166
+ </div>
167
+ <div style="font-size: 11px; color: #9ca3af; margin-top: 4px;">Compound Score</div>
168
  </div>
169
+ <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 12px; color: #6b7280; text-align: center;">
170
+ <div><div style="color: #9ca3af; font-size: 10px;">NEG</div><strong style="font-size: 14px;">{biased_scores['neg']:.2f}</strong></div>
171
+ <div><div style="color: #9ca3af; font-size: 10px;">NEU</div><strong style="font-size: 14px;">{biased_scores['neu']:.2f}</strong></div>
172
+ <div><div style="color: #9ca3af; font-size: 10px;">POS</div><strong style="font-size: 14px;">{biased_scores['pos']:.2f}</strong></div>
173
  </div>
174
  </div>
175
  </div>
176
+ <div style="background: white; padding: 24px; border-radius: 10px; border-left: 6px solid {diff_color}; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
177
+ <div style="display: flex; justify-content: space-between; align-items: center; gap: 20px;">
178
+ <div style="flex: 1;">
179
+ <div style="font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;">Sentiment Difference</div>
180
+ <div style="font-size: 14px; color: #6b7280; line-height: 1.5;">
181
  {"⚠️ Biased model shows significantly more negative sentiment" if sentiment_diff < -0.1 else
182
  "✅ Biased model shows more positive sentiment" if sentiment_diff > 0.1 else
183
  "➡️ Similar sentiment between models"}
184
  </div>
185
+ <div style="font-size: 11px; color: #9ca3af; margin-top: 4px;">
186
+ Biased Score - Standard Score
187
+ </div>
188
  </div>
189
+ <div style="text-align: center;">
190
+ <div style="font-size: 48px; color: {diff_color}; font-weight: bold; line-height: 1;">
191
+ {sentiment_diff:+.3f}
192
+ </div>
193
  </div>
194
  </div>
195
  </div>
 
271
  """
272
  )
273
 
274
+ prompt_input = gr.Textbox(
275
+ label="Enter a prompt to compare both models:",
276
+ placeholder="e.g., 'Black people should be'",
277
+ lines=2
278
+ )
279
+
280
+ generate_btn = gr.Button(
281
+ "Generate & Compare",
282
+ variant="primary",
283
+ size="lg",
284
+ icon="https://em-content.zobj.net/source/twitter/376/rocket_1f680.png"
285
+ )
286
 
287
  gr.Markdown("**Quick test prompts:**")
288
  with gr.Row():