realArceus commited on
Commit
415770d
Β·
verified Β·
1 Parent(s): ea443f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +246 -43
app.py CHANGED
@@ -138,12 +138,12 @@ def build_trace(problem, displayed, first_fail, done=False):
138
  lbl, conf = probe_step(problem, displayed[:i+1])
139
  if lbl == "FAIL": faults += 1
140
  dot = f"<span class='dot dot-{'ok' if lbl == 'OK' else 'fail'}'></span>"
141
- rows += f"<div class='trace-row'>{dot} Step {i+1} &mdash; {int(conf*100)}%</div>"
142
  else:
143
  rows += "<div class='trace-row'><span class='dot dot-final'></span> Final Answer</div>"
144
 
145
  health = max(0, 100 - faults * 20)
146
- bar_color = "#16a34a" if health > 60 else "#dc2626"
147
  summary = f"""
148
  <div class='trace-summary'>
149
  <div class='trace-label'>Reasoning Health</div>
@@ -153,50 +153,245 @@ def build_trace(problem, displayed, first_fail, done=False):
153
  return f"{rows}{summary}"
154
 
155
 
156
- # ── CSS ───────────────────────────────────────────────────────────────────────
157
  CSS = """
158
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
 
 
159
  *, *::before, *::after { box-sizing: border-box; }
160
- body, .gradio-container, .gradio-container * { font-family: 'Inter', sans-serif !important; }
161
- .gradio-container { background: #f8fafc !important; max-width: 1200px !important; }
162
- .twt-header { text-align: center; padding: 2rem 1rem 1.25rem; border-bottom: 2px solid #e2e8f0; margin-bottom: 1.5rem; background: #ffffff; border-radius: 12px 12px 0 0; }
163
- .twt-title { font-size: 2rem; font-weight: 700; letter-spacing: -0.04em; color: #0f172a; font-family: 'JetBrains Mono', monospace !important; }
164
- .twt-title span { color: #7c3aed; }
165
- .twt-sub { font-size: 0.75rem; color: #94a3b8; margin-top: 0.35rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 500; }
166
- .input-label { font-size: 0.7rem; font-weight: 700; color: #64748b; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 0.4rem; }
167
- textarea { background: #ffffff !important; border: 1.5px solid #cbd5e1 !important; border-radius: 8px !important; color: #0f172a !important; font-size: 0.95rem !important; line-height: 1.6 !important; transition: border-color 0.15s !important; padding: 0.75rem !important; }
168
- textarea:focus { border-color: #7c3aed !important; box-shadow: 0 0 0 3px rgba(124,58,237,0.1) !important; outline: none !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  textarea::placeholder { color: #94a3b8 !important; }
170
- button.primary { background: #7c3aed !important; color: #ffffff !important; font-weight: 600 !important; font-family: 'Inter', sans-serif !important; border: none !important; border-radius: 8px !important; padding: 0.65rem 1.5rem !important; font-size: 0.9rem !important; transition: background 0.15s, transform 0.1s !important; cursor: pointer !important; width: 100% !important; }
171
- button.primary:hover { background: #6d28d9 !important; transform: translateY(-1px) !important; }
172
- .panel-label { font-size: 0.68rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.12em; margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 2px solid #e2e8f0; }
173
- .step-card { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.75rem 1rem; margin-bottom: 0.5rem; background: #ffffff; border: 1.5px solid #e2e8f0; border-radius: 8px; font-size: 0.875rem; line-height: 1.65; animation: fadeUp 0.2s ease both; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
174
- .step-card.step-fault { border-color: #fca5a5; background: #fff5f5; }
175
- @keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
176
- .step-icon { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }
177
- .step-text { flex: 1; color: #1e293b; font-family: 'Inter', sans-serif !important; font-size: 0.875rem; }
178
- .badge { flex-shrink: 0; font-size: 0.62rem; font-weight: 700; font-family: 'JetBrains Mono', monospace !important; letter-spacing: 0.04em; padding: 0.18rem 0.5rem; border-radius: 4px; align-self: flex-start; margin-top: 3px; }
179
- .badge-ok { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
180
- .badge-fail { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
181
- .badge-final { background: #ede9fe; color: #6d28d9; border: 1px solid #c4b5fd; }
182
- .trace-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.78rem; color: #475569; font-family: 'JetBrains Mono', monospace !important; padding: 0.35rem 0; border-bottom: 1px solid #f1f5f9; }
183
- .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
184
- .dot-ok { background: #22c55e; }
185
- .dot-fail { background: #ef4444; box-shadow: 0 0 5px rgba(239,68,68,0.4); }
186
- .dot-final { background: #7c3aed; }
187
- .trace-summary { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid #e2e8f0; }
188
- .trace-label { font-size: 0.65rem; font-weight: 700; color: #64748b; text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.5rem; }
189
- .trace-bar-bg { background: #e2e8f0; border-radius: 999px; height: 6px; overflow: hidden; }
190
- .trace-bar { height: 100%; border-radius: 999px; transition: width 0.6s ease; }
191
- .trace-pct { font-size: 0.72rem; color: #475569; margin-top: 0.3rem; font-family: 'JetBrains Mono', monospace !important; font-weight: 500; }
192
- .msg { padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.85rem; }
193
- .msg.warn { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }
194
- .msg.error { background: #fff5f5; color: #b91c1c; border: 1px solid #fca5a5; }
195
- .msg.empty { color: #94a3b8; font-size: 0.8rem; font-family: 'JetBrains Mono', monospace !important; padding: 1rem; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  .gradio-container .prose { color: #1e293b !important; }
197
- label span { color: #374151 !important; font-size: 0.85rem !important; }
198
  """
199
 
 
200
  HEADER = """
201
  <div class='twt-header'>
202
  <div class='twt-title'>Think<span>While</span>Thinking</div>
@@ -216,17 +411,25 @@ with gr.Blocks(css=CSS, title="ThinkWhileThinking") as demo:
216
  with gr.Row():
217
  with gr.Column(scale=2):
218
  gr.HTML("<div class='input-label'>Problem</div>")
219
- problem_input = gr.Textbox(placeholder="Enter a math, logic, or reasoning problem...", lines=5, show_label=False)
 
 
 
 
220
  run_btn = gr.Button("β–Ά Analyze Reasoning", variant="primary")
221
  gr.Examples(examples=EXAMPLES, inputs=problem_input, label="Try an example")
222
  with gr.Column(scale=3):
223
  with gr.Row():
224
  with gr.Column(scale=3):
225
  gr.HTML("<div class='panel-label'>Chain of Thought Β· Step Scores</div>")
226
- cot_output = gr.HTML(value="<div class='msg empty'>// awaiting problem input</div>")
 
 
227
  with gr.Column(scale=1):
228
  gr.HTML("<div class='panel-label'>Step Trace</div>")
229
- trace_output = gr.HTML(value="<div class='msg empty'>// trace</div>")
 
 
230
  raw_output = gr.Textbox(visible=False)
231
  run_btn.click(fn=run_twt, inputs=[problem_input], outputs=[raw_output, cot_output, trace_output])
232
  problem_input.submit(fn=run_twt, inputs=[problem_input], outputs=[raw_output, cot_output, trace_output])
 
138
  lbl, conf = probe_step(problem, displayed[:i+1])
139
  if lbl == "FAIL": faults += 1
140
  dot = f"<span class='dot dot-{'ok' if lbl == 'OK' else 'fail'}'></span>"
141
+ rows += f"<div class='trace-row'>{dot} Step {i+1} <span class='trace-conf'>&mdash; {int(conf*100)}%</span></div>"
142
  else:
143
  rows += "<div class='trace-row'><span class='dot dot-final'></span> Final Answer</div>"
144
 
145
  health = max(0, 100 - faults * 20)
146
+ bar_color = "#10b981" if health > 60 else "#ef4444"
147
  summary = f"""
148
  <div class='trace-summary'>
149
  <div class='trace-label'>Reasoning Health</div>
 
153
  return f"{rows}{summary}"
154
 
155
 
156
+ # ── CSS (SaaS / Modern Professional Upgrade) ──────────────────────────────────
157
  CSS = """
158
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
159
+
160
+ /* Globals */
161
  *, *::before, *::after { box-sizing: border-box; }
162
+ body, .gradio-container, .gradio-container * {
163
+ font-family: 'Inter', -apple-system, sans-serif !important;
164
+ }
165
+ .gradio-container {
166
+ background-color: #f8fafc !important;
167
+ max-width: 1280px !important;
168
+ }
169
+
170
+ /* Header */
171
+ .twt-header {
172
+ text-align: center;
173
+ padding: 3rem 1rem 2rem;
174
+ margin-bottom: 2.5rem;
175
+ background: transparent;
176
+ border-bottom: 1px solid #e2e8f0;
177
+ }
178
+ .twt-title {
179
+ font-size: 2.75rem;
180
+ font-weight: 800;
181
+ letter-spacing: -0.04em;
182
+ color: #0f172a;
183
+ font-family: 'JetBrains Mono', monospace !important;
184
+ margin-bottom: 0.5rem;
185
+ }
186
+ .twt-title span {
187
+ background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
188
+ -webkit-background-clip: text;
189
+ -webkit-text-fill-color: transparent;
190
+ }
191
+ .twt-sub {
192
+ font-size: 0.85rem;
193
+ color: #64748b;
194
+ letter-spacing: 0.05em;
195
+ font-weight: 500;
196
+ }
197
+
198
+ /* Typography & Labels */
199
+ .input-label, .panel-label {
200
+ font-size: 0.75rem;
201
+ font-weight: 700;
202
+ color: #475569;
203
+ letter-spacing: 0.1em;
204
+ text-transform: uppercase;
205
+ margin-bottom: 0.75rem;
206
+ display: block;
207
+ }
208
+ .panel-label {
209
+ padding-bottom: 0.5rem;
210
+ border-bottom: 2px solid #e2e8f0;
211
+ }
212
+
213
+ /* Inputs & Forms */
214
+ textarea {
215
+ background: #ffffff !important;
216
+ border: 1px solid #cbd5e1 !important;
217
+ border-radius: 12px !important;
218
+ color: #0f172a !important;
219
+ font-size: 0.95rem !important;
220
+ line-height: 1.6 !important;
221
+ padding: 1rem !important;
222
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
223
+ transition: all 0.2s ease-in-out !important;
224
+ }
225
+ textarea:focus {
226
+ border-color: #7c3aed !important;
227
+ box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15) !important;
228
+ outline: none !important;
229
+ }
230
  textarea::placeholder { color: #94a3b8 !important; }
231
+
232
+ /* Primary Button */
233
+ button.primary {
234
+ background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%) !important;
235
+ color: #ffffff !important;
236
+ font-weight: 600 !important;
237
+ border: none !important;
238
+ border-radius: 10px !important;
239
+ padding: 0.75rem 1.5rem !important;
240
+ font-size: 0.95rem !important;
241
+ letter-spacing: 0.02em !important;
242
+ box-shadow: 0 4px 6px -1px rgba(124, 58, 237, 0.3), 0 2px 4px -1px rgba(124, 58, 237, 0.2) !important;
243
+ transition: all 0.2s ease !important;
244
+ cursor: pointer !important;
245
+ width: 100% !important;
246
+ }
247
+ button.primary:hover {
248
+ transform: translateY(-2px) !important;
249
+ box-shadow: 0 10px 15px -3px rgba(124, 58, 237, 0.3), 0 4px 6px -2px rgba(124, 58, 237, 0.2) !important;
250
+ }
251
+ button.primary:active {
252
+ transform: translateY(0) !important;
253
+ }
254
+
255
+ /* Step Cards */
256
+ .step-card {
257
+ display: flex;
258
+ align-items: flex-start;
259
+ gap: 1rem;
260
+ padding: 1.25rem;
261
+ margin-bottom: 0.75rem;
262
+ background: #ffffff;
263
+ border: 1px solid #e2e8f0;
264
+ border-radius: 12px;
265
+ font-size: 0.9rem;
266
+ line-height: 1.6;
267
+ animation: fadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
268
+ box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
269
+ transition: box-shadow 0.2s ease, border-color 0.2s ease;
270
+ }
271
+ .step-card:hover {
272
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
273
+ border-color: #cbd5e1;
274
+ }
275
+ .step-card.step-fault {
276
+ border: 1px solid #fecaca;
277
+ background: #fff1f2;
278
+ }
279
+ .step-card.step-fault:hover {
280
+ border-color: #fca5a5;
281
+ }
282
+
283
+ @keyframes fadeUp {
284
+ from { opacity: 0; transform: translateY(12px); }
285
+ to { opacity: 1; transform: translateY(0); }
286
+ }
287
+
288
+ .step-icon {
289
+ font-size: 1.1rem;
290
+ flex-shrink: 0;
291
+ margin-top: 2px;
292
+ }
293
+ .step-text {
294
+ flex: 1;
295
+ color: #1e293b;
296
+ }
297
+
298
+ /* Badges */
299
+ .badge {
300
+ flex-shrink: 0;
301
+ font-size: 0.65rem;
302
+ font-weight: 700;
303
+ font-family: 'JetBrains Mono', monospace !important;
304
+ letter-spacing: 0.05em;
305
+ padding: 0.25rem 0.75rem;
306
+ border-radius: 999px; /* Pill shape */
307
+ align-self: flex-start;
308
+ margin-top: 2px;
309
+ }
310
+ .badge-ok { background: #ecfdf5; color: #059669; border: 1px solid #a7f3d0; }
311
+ .badge-fail { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
312
+ .badge-final { background: #f3e8ff; color: #7c3aed; border: 1px solid #d8b4fe; }
313
+
314
+ /* Trace Panel */
315
+ .trace-row {
316
+ display: flex;
317
+ align-items: center;
318
+ gap: 0.75rem;
319
+ font-size: 0.8rem;
320
+ color: #334155;
321
+ font-family: 'JetBrains Mono', monospace !important;
322
+ padding: 0.5rem 0;
323
+ border-bottom: 1px solid #f1f5f9;
324
+ }
325
+ .trace-conf {
326
+ color: #94a3b8;
327
+ font-weight: 500;
328
+ }
329
+ .dot {
330
+ width: 10px; height: 10px;
331
+ border-radius: 50%;
332
+ flex-shrink: 0;
333
+ }
334
+ .dot-ok { background: #10b981; box-shadow: 0 0 0 3px #d1fae5; }
335
+ .dot-fail { background: #ef4444; box-shadow: 0 0 0 3px #fee2e2; }
336
+ .dot-final { background: #8b5cf6; box-shadow: 0 0 0 3px #ede9fe; }
337
+
338
+ .trace-summary {
339
+ margin-top: 1.5rem;
340
+ padding-top: 1rem;
341
+ border-top: 1px solid #e2e8f0;
342
+ }
343
+ .trace-label {
344
+ font-size: 0.7rem;
345
+ font-weight: 700;
346
+ color: #475569;
347
+ text-transform: uppercase;
348
+ letter-spacing: 0.1em;
349
+ margin-bottom: 0.5rem;
350
+ }
351
+ .trace-bar-bg {
352
+ background: #e2e8f0;
353
+ border-radius: 999px;
354
+ height: 8px;
355
+ overflow: hidden;
356
+ }
357
+ .trace-bar {
358
+ height: 100%;
359
+ border-radius: 999px;
360
+ transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
361
+ }
362
+ .trace-pct {
363
+ font-size: 0.75rem;
364
+ color: #334155;
365
+ margin-top: 0.4rem;
366
+ font-family: 'JetBrains Mono', monospace !important;
367
+ font-weight: 600;
368
+ }
369
+
370
+ /* System Messages */
371
+ .msg {
372
+ padding: 1rem 1.25rem;
373
+ border-radius: 10px;
374
+ font-size: 0.85rem;
375
+ font-weight: 500;
376
+ }
377
+ .msg.warn { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
378
+ .msg.error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
379
+ .msg.empty {
380
+ color: #94a3b8;
381
+ font-size: 0.85rem;
382
+ font-family: 'JetBrains Mono', monospace !important;
383
+ padding: 1.5rem 1rem;
384
+ text-align: center;
385
+ border: 1px dashed #cbd5e1;
386
+ border-radius: 12px;
387
+ }
388
+
389
+ /* Gradio Overrides */
390
  .gradio-container .prose { color: #1e293b !important; }
391
+ .gr-box, .gr-form { background: transparent !important; border: none !important; }
392
  """
393
 
394
+ # ── Layout ────────────────────────────────────────────────────────────────────
395
  HEADER = """
396
  <div class='twt-header'>
397
  <div class='twt-title'>Think<span>While</span>Thinking</div>
 
411
  with gr.Row():
412
  with gr.Column(scale=2):
413
  gr.HTML("<div class='input-label'>Problem</div>")
414
+ problem_input = gr.Textbox(
415
+ placeholder="Enter a math, logic, or reasoning problem...",
416
+ lines=5,
417
+ show_label=False,
418
+ )
419
  run_btn = gr.Button("β–Ά Analyze Reasoning", variant="primary")
420
  gr.Examples(examples=EXAMPLES, inputs=problem_input, label="Try an example")
421
  with gr.Column(scale=3):
422
  with gr.Row():
423
  with gr.Column(scale=3):
424
  gr.HTML("<div class='panel-label'>Chain of Thought Β· Step Scores</div>")
425
+ cot_output = gr.HTML(
426
+ value="<div class='msg empty'>// awaiting problem input</div>"
427
+ )
428
  with gr.Column(scale=1):
429
  gr.HTML("<div class='panel-label'>Step Trace</div>")
430
+ trace_output = gr.HTML(
431
+ value="<div class='msg empty'>// trace</div>"
432
+ )
433
  raw_output = gr.Textbox(visible=False)
434
  run_btn.click(fn=run_twt, inputs=[problem_input], outputs=[raw_output, cot_output, trace_output])
435
  problem_input.submit(fn=run_twt, inputs=[problem_input], outputs=[raw_output, cot_output, trace_output])