akshay4 commited on
Commit
96cda89
Β·
verified Β·
1 Parent(s): 4e8e273

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +101 -14
  2. witgym/debug_render.py +48 -19
app.py CHANGED
@@ -66,15 +66,16 @@ CHARACTERS = [
66
  STARTERS = [
67
  ("Status", "I just got promoted to manager and I have no idea what I'm doing."),
68
  ("Social", "My coworker keeps stealing my lunch from the fridge."),
69
- ("Awkward", "I've been cc'd on an email chain I definitely should not be reading."),
70
  ("Delusion", "I'm pretending to understand cryptocurrency at dinner parties."),
71
- ("Confidence", "I give excellent feedback. People just don't know how to receive it."),
72
  ("Anxiety", "I've been ignoring a voicemail so long it feels like a legal risk."),
73
- ("Procrastination","I went to bed early last night."),
74
- ("Self-awareness", "I sent a complaint about my manager to my manager."),
75
  ("Coach me", "Help me respond when someone asks about my job and I don't know what to say."),
76
- ("Comeback", "How would you handle it if someone called you 'surprisingly competent'?"),
77
- ("Explain", "Teach me why it's funny when someone gives a backhanded compliment."),
 
 
 
 
78
  ]
79
 
80
  TRANSCRIPT_MIN_HEIGHT = 440
@@ -747,6 +748,42 @@ body.wg-light-mode footer { background: #fffff8 !important; }
747
  #wg-practice .wg-twist-score { color: #b45309 !important; }
748
  #wg-practice .wg-twist-label { color: #9e9288 !important; }
749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  /* ── Persona label + another-take ──────────────────────────────────────── */
751
  .wg-persona-label {
752
  font-style: italic; font-family: 'EB Garamond', serif;
@@ -795,6 +832,20 @@ body.wg-light-mode footer { background: #fffff8 !important; }
795
  #wg-practice { position: relative; }
796
 
797
  /* ── Comic-style modal ──────────────────────────────────────────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
  #wg-modal-overlay {
799
  position: fixed; inset: 0; z-index: 9999;
800
  background: rgba(0,0,0,0.65); backdrop-filter: blur(5px);
@@ -820,7 +871,7 @@ body.wg-light-mode footer { background: #fffff8 !important; }
820
  .wg-modal-x:hover { background: #333; }
821
  .wg-pop-show {
822
  font-family: 'Bebas Neue', sans-serif; font-size: 1rem;
823
- letter-spacing: 0.2em; color: #2d6a4f; margin-bottom: 1rem;
824
  border-bottom: 2px solid #e0d8cc; padding-bottom: 0.5rem;
825
  }
826
  .wg-pop-row { display: flex; gap: 1.25rem; margin-bottom: 1rem; align-items: flex-start; }
@@ -828,21 +879,21 @@ body.wg-light-mode footer { background: #fffff8 !important; }
828
  .wg-pop-avatar { width: 110px; height: 110px; border-radius: 12px; background: #f5f0e6; }
829
  .wg-pop-name {
830
  font-family: 'Bebas Neue', sans-serif; font-size: 1rem;
831
- letter-spacing: 0.08em; color: #2a2118; text-align: center;
832
  }
833
  .wg-pop-title {
834
- font-size: 0.72rem; color: #9e9288; text-align: center; font-style: italic;
835
  max-width: 110px; line-height: 1.3;
836
  }
837
  .wg-pop-right { flex: 1; display: flex; flex-direction: column; gap: 0.65rem; }
838
  .wg-pop-setup {
839
- font-style: italic; color: #6b6258; font-size: 0.95rem; line-height: 1.5;
840
  }
841
  .wg-pop-bubble {
842
  background: #fff; border: 2.5px solid #1a1a1a; border-radius: 14px;
843
  padding: 0.85rem 1rem;
844
  font-family: 'Bebas Neue', Impact, sans-serif;
845
- font-size: 1.15rem; line-height: 1.3; letter-spacing: 0.02em; color: #1a1a1a;
846
  position: relative;
847
  }
848
  .wg-pop-bubble::before {
@@ -859,12 +910,12 @@ body.wg-light-mode footer { background: #fffff8 !important; }
859
  }
860
  .wg-pop-why-title {
861
  font-family: 'Bebas Neue', sans-serif; font-size: 0.82rem;
862
- letter-spacing: 0.12em; color: #2563eb; margin-bottom: 0.35rem;
863
  }
864
- .wg-pop-why-body { font-size: 0.95rem; color: #1e3a5f; line-height: 1.55; }
865
  /* Bio modal (character card click β€” no scene context) */
866
  .wg-pop-bio {
867
- font-size: 1.05rem; color: #3d3429; line-height: 1.6; font-style: italic;
868
  background: #f5f0e6; border-left: 3px solid #2d6a4f;
869
  padding: 0.75rem 1rem; border-radius: 0 10px 10px 0;
870
  }
@@ -972,6 +1023,34 @@ window.wgPlayClack = function() {
972
  observe();
973
  })();
974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
975
  window.wgClose = function() {
976
  var o = document.getElementById('wg-modal-overlay');
977
  if (o) o.style.display = 'none';
@@ -1140,6 +1219,7 @@ def _practice_header_html() -> str:
1140
  '<div class="wg-practice-bar">'
1141
  '<div class="wg-practice-logo">WIT<span>GYM</span></div>'
1142
  '<div class="wg-practice-sub">Comedy Coaching Engine</div>'
 
1143
  '</div>'
1144
  )
1145
 
@@ -1302,6 +1382,13 @@ def build_ui():
1302
  elem_classes=["wg-starter-btn"],
1303
  )
1304
  sb.click(fn=fill_starter, inputs=[gr.State(text)], outputs=user_input, queue=False)
 
 
 
 
 
 
 
1305
 
1306
  # ── Event wiring ──────────────────────────────────────────
1307
  start_btn.click(
 
66
  STARTERS = [
67
  ("Status", "I just got promoted to manager and I have no idea what I'm doing."),
68
  ("Social", "My coworker keeps stealing my lunch from the fridge."),
 
69
  ("Delusion", "I'm pretending to understand cryptocurrency at dinner parties."),
 
70
  ("Anxiety", "I've been ignoring a voicemail so long it feels like a legal risk."),
71
+ ("Self-aware", "I sent a complaint about my manager to my manager."),
 
72
  ("Coach me", "Help me respond when someone asks about my job and I don't know what to say."),
73
+ ]
74
+
75
+ DRILL_ACTIONS = [
76
+ ("sharpen it", "Make that line sharper and more cutting"),
77
+ ("different angle", "Give me a completely different angle on the same situation"),
78
+ ("explain the joke", "Explain why that line works β€” what comedy principle does it use?"),
79
  ]
80
 
81
  TRANSCRIPT_MIN_HEIGHT = 440
 
748
  #wg-practice .wg-twist-score { color: #b45309 !important; }
749
  #wg-practice .wg-twist-label { color: #9e9288 !important; }
750
 
751
+ /* ── Rep counter ────────────────────────────────────────────────────────── */
752
+ .wg-rep-count {
753
+ font-family: 'Bebas Neue', sans-serif; font-size: 0.72rem;
754
+ letter-spacing: 0.2em; color: var(--wg-green); padding: 0.1rem 0.5rem;
755
+ border: 1px solid rgba(45,106,79,0.35); border-radius: 20px;
756
+ background: rgba(45,106,79,0.06);
757
+ transition: opacity .3s;
758
+ }
759
+ .wg-rep-count:empty { display: none; }
760
+
761
+ /* ── Drill chips ─────────────────────────────────────────────────────────── */
762
+ .wg-drill-chips {
763
+ display: flex; flex-wrap: wrap; gap: 0.45rem;
764
+ margin: 0.6rem 0 0.2rem;
765
+ }
766
+ .wg-drill-chip {
767
+ font-family: 'EB Garamond', serif; font-style: italic;
768
+ font-size: 0.82rem; cursor: pointer; user-select: none;
769
+ padding: 0.22rem 0.7rem; border-radius: 20px;
770
+ border: 1px solid var(--wg-border); color: var(--wg-muted);
771
+ background: var(--wg-surf2);
772
+ transition: border-color .15s, color .15s, background .15s;
773
+ }
774
+ .wg-drill-chip:hover {
775
+ border-color: var(--wg-yellow); color: var(--wg-yellow);
776
+ background: rgba(245,197,24,0.06);
777
+ }
778
+ #wg-practice .wg-drill-chip {
779
+ border-color: #e0d8cc !important; color: #9e9288 !important;
780
+ background: #f5f2eb !important;
781
+ }
782
+ #wg-practice .wg-drill-chip:hover {
783
+ border-color: #b45309 !important; color: #b45309 !important;
784
+ background: rgba(180,83,9,0.06) !important;
785
+ }
786
+
787
  /* ── Persona label + another-take ──────────────────────────────────────── */
788
  .wg-persona-label {
789
  font-style: italic; font-family: 'EB Garamond', serif;
 
832
  #wg-practice { position: relative; }
833
 
834
  /* ── Comic-style modal ──────────────────────────────────────────────────── */
835
+ /* Same structural fix as #wg-practice: Gradio injects
836
+ .prose * { color: var(--body-text-color) } which resolves to #f0f0f0 (dark
837
+ theme) on every child element. The modal is outside #wg-practice so that
838
+ scope doesn't apply. Override the same Gradio CSS vars here so child text
839
+ inherits dark-on-ivory correctly β€” no per-element !important hacks needed. */
840
+ #wg-modal {
841
+ --body-text-color: #2a2118;
842
+ --body-text-color-subdued: #6b6258;
843
+ --block-text-color: #2a2118;
844
+ --block-label-text-color: #6b6258;
845
+ --input-text: #2a2118;
846
+ --color-text-body: #2a2118;
847
+ color: #2a2118;
848
+ }
849
  #wg-modal-overlay {
850
  position: fixed; inset: 0; z-index: 9999;
851
  background: rgba(0,0,0,0.65); backdrop-filter: blur(5px);
 
871
  .wg-modal-x:hover { background: #333; }
872
  .wg-pop-show {
873
  font-family: 'Bebas Neue', sans-serif; font-size: 1rem;
874
+ letter-spacing: 0.2em; color: #2d6a4f !important; margin-bottom: 1rem;
875
  border-bottom: 2px solid #e0d8cc; padding-bottom: 0.5rem;
876
  }
877
  .wg-pop-row { display: flex; gap: 1.25rem; margin-bottom: 1rem; align-items: flex-start; }
 
879
  .wg-pop-avatar { width: 110px; height: 110px; border-radius: 12px; background: #f5f0e6; }
880
  .wg-pop-name {
881
  font-family: 'Bebas Neue', sans-serif; font-size: 1rem;
882
+ letter-spacing: 0.08em; color: #2a2118 !important; text-align: center;
883
  }
884
  .wg-pop-title {
885
+ font-size: 0.72rem; color: #9e9288 !important; text-align: center; font-style: italic;
886
  max-width: 110px; line-height: 1.3;
887
  }
888
  .wg-pop-right { flex: 1; display: flex; flex-direction: column; gap: 0.65rem; }
889
  .wg-pop-setup {
890
+ font-style: italic; color: #6b6258 !important; font-size: 0.95rem; line-height: 1.5;
891
  }
892
  .wg-pop-bubble {
893
  background: #fff; border: 2.5px solid #1a1a1a; border-radius: 14px;
894
  padding: 0.85rem 1rem;
895
  font-family: 'Bebas Neue', Impact, sans-serif;
896
+ font-size: 1.15rem; line-height: 1.3; letter-spacing: 0.02em; color: #1a1a1a !important;
897
  position: relative;
898
  }
899
  .wg-pop-bubble::before {
 
910
  }
911
  .wg-pop-why-title {
912
  font-family: 'Bebas Neue', sans-serif; font-size: 0.82rem;
913
+ letter-spacing: 0.12em; color: #2563eb !important; margin-bottom: 0.35rem;
914
  }
915
+ .wg-pop-why-body { font-size: 0.95rem; color: #1e3a5f !important; line-height: 1.55; }
916
  /* Bio modal (character card click β€” no scene context) */
917
  .wg-pop-bio {
918
+ font-size: 1.05rem; color: #3d3429 !important; line-height: 1.6; font-style: italic;
919
  background: #f5f0e6; border-left: 3px solid #2d6a4f;
920
  padding: 0.75rem 1rem; border-radius: 0 10px 10px 0;
921
  }
 
1023
  observe();
1024
  })();
1025
 
1026
+ /* Drill chip: prefill textbox and focus it */
1027
+ window.wgDrill = function(text) {
1028
+ var ta = document.querySelector('#wg-chat-shell textarea');
1029
+ if (!ta) return;
1030
+ var setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value');
1031
+ if (setter && setter.set) setter.set.call(ta, text);
1032
+ ta.dispatchEvent(new Event('input', { bubbles: true }));
1033
+ ta.focus();
1034
+ ta.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
1035
+ };
1036
+
1037
+ /* Rep counter: count completed (non-thinking) turns */
1038
+ (function(){
1039
+ function updateRep() {
1040
+ var turns = document.querySelectorAll('.wg-turn:not(.wg-turn--thinking)');
1041
+ var el = document.getElementById('wg-rep-count');
1042
+ if (!el) return;
1043
+ el.textContent = turns.length > 0 ? 'REP ' + turns.length : '';
1044
+ }
1045
+ function watchTranscript() {
1046
+ var t = document.querySelector('.wg-transcript');
1047
+ if (!t) { setTimeout(watchTranscript, 600); return; }
1048
+ new MutationObserver(updateRep).observe(t, {childList: true, subtree: true});
1049
+ updateRep();
1050
+ }
1051
+ watchTranscript();
1052
+ })();
1053
+
1054
  window.wgClose = function() {
1055
  var o = document.getElementById('wg-modal-overlay');
1056
  if (o) o.style.display = 'none';
 
1219
  '<div class="wg-practice-bar">'
1220
  '<div class="wg-practice-logo">WIT<span>GYM</span></div>'
1221
  '<div class="wg-practice-sub">Comedy Coaching Engine</div>'
1222
+ '<span id="wg-rep-count" class="wg-rep-count" aria-live="polite"></span>'
1223
  '</div>'
1224
  )
1225
 
 
1382
  elem_classes=["wg-starter-btn"],
1383
  )
1384
  sb.click(fn=fill_starter, inputs=[gr.State(text)], outputs=user_input, queue=False)
1385
+ gr.HTML('<div class="wg-sidebar-label" style="margin-top:.85rem">Coach drills</div>')
1386
+ for label, drill_text in DRILL_ACTIONS:
1387
+ db = gr.Button(
1388
+ f"↻ {label}", size="sm", variant="secondary",
1389
+ elem_classes=["wg-starter-btn"],
1390
+ )
1391
+ db.click(fn=fill_starter, inputs=[gr.State(drill_text)], outputs=user_input, queue=False)
1392
 
1393
  # ── Event wiring ──────────────────────────────────────────
1394
  start_btn.click(
witgym/debug_render.py CHANGED
@@ -363,33 +363,46 @@ def format_streaming_turn_html(state: StreamingTurnState, show_debug: bool = Tru
363
  if state.winning_persona else ""
364
  )
365
 
366
- parts += [
367
- _twist_meter_html(state.metadata.twist_potential),
368
- '<div class="wg-debug-toggle wg-debug-toggle--new">',
369
- '<span class="wg-debug-toggle-line"></span>',
370
- f'<span class="wg-debug-toggle-label">Coaching notes <span class="wg-debug-chevron">{chevron}</span></span>',
371
- '<span class="wg-debug-toggle-line"></span>',
372
- '</div>',
373
- f'<div class="wg-debug-body{collapsed_cls}">',
374
- _streaming_debug_panels_html(state, state.selected),
375
- '</div>',
376
- ]
377
 
378
- if display_text:
 
 
379
  polish = ' Β· <span class="wg-dim-italic">polishing…</span>' if state.streaming_final else ""
380
  parts += [
381
- _mode_badge_html(state.route),
382
  '<div class="wg-coach-reply wg-coach-reply--new">',
383
  f'<div class="wg-coach-reply-header">Your humor coach{persona_label}{polish}</div>',
384
  f'<div class="wg-coach-reply-body">{_esc(display_text)}</div>',
385
  '</div>',
386
  ]
 
 
 
 
 
 
 
 
387
  elif not state.active_persona:
388
  parts += [
389
  f'<div class="wg-thinking">{_THINKING_ICON}'
390
  '<span>drafting candidates…</span></div>',
391
  ]
392
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
  parts.append('<div class="wg-rule"></div></div>')
394
  return "".join(parts)
395
 
@@ -473,8 +486,30 @@ def format_trace_html(result: WitGymResponse, user_input: str, show_debug: bool
473
  new_cls = " wg-coach-reply--new" if is_last else ""
474
 
475
  beckon_cls = " wg-debug-toggle--new" if is_last else ""
 
 
476
  parts += [
477
  _mode_badge_html(result.route),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  _twist_meter_html(result.metadata.twist_potential),
479
  f'<div class="wg-debug-toggle{beckon_cls}">',
480
  '<span class="wg-debug-toggle-line"></span>',
@@ -484,13 +519,7 @@ def format_trace_html(result: WitGymResponse, user_input: str, show_debug: bool
484
  f'<div class="wg-debug-body{collapsed_cls}">',
485
  _debug_panels_html(result),
486
  '</div>',
487
- f'<div class="wg-coach-reply{new_cls}" data-alts="{alts_json}" data-alt-idx="0">',
488
- f'<div class="wg-coach-reply-header">Your humor coach{persona_label}{another_take_btn}</div>',
489
- f'<div class="wg-coach-reply-body">{_esc(result.selected)}</div>',
490
- '</div>',
491
  ]
492
- if result.explanation:
493
- parts.append(_explanation_panel_html(result.explanation))
494
  parts.append('<div class="wg-rule"></div></div>')
495
  return "".join(parts)
496
 
 
363
  if state.winning_persona else ""
364
  )
365
 
366
+ # Guard: don't display raw JSON tokens that leak during compress_winner_stream
367
+ is_raw_json = bool(display_text and display_text.lstrip().startswith("{"))
 
 
 
 
 
 
 
 
 
368
 
369
+ # ── Hero reply FIRST (above fold) ──────────────────────────────────────
370
+ parts.append(_mode_badge_html(state.route))
371
+ if display_text and not is_raw_json:
372
  polish = ' Β· <span class="wg-dim-italic">polishing…</span>' if state.streaming_final else ""
373
  parts += [
 
374
  '<div class="wg-coach-reply wg-coach-reply--new">',
375
  f'<div class="wg-coach-reply-header">Your humor coach{persona_label}{polish}</div>',
376
  f'<div class="wg-coach-reply-body">{_esc(display_text)}</div>',
377
  '</div>',
378
  ]
379
+ elif state.streaming_final or is_raw_json:
380
+ # Compression pass running β€” show stable placeholder
381
+ parts += [
382
+ '<div class="wg-coach-reply wg-coach-reply--new">',
383
+ f'<div class="wg-coach-reply-header">Your humor coach{persona_label} Β· <span class="wg-dim-italic">polishing…</span></div>',
384
+ f'<div class="wg-coach-reply-body wg-dim-italic">Finding the sharpest version…</div>',
385
+ '</div>',
386
+ ]
387
  elif not state.active_persona:
388
  parts += [
389
  f'<div class="wg-thinking">{_THINKING_ICON}'
390
  '<span>drafting candidates…</span></div>',
391
  ]
392
 
393
+ # ── Process rail SECOND (compact, below hero) ──────────────────────────
394
+ parts += [
395
+ _twist_meter_html(state.metadata.twist_potential),
396
+ '<div class="wg-debug-toggle wg-debug-toggle--new">',
397
+ '<span class="wg-debug-toggle-line"></span>',
398
+ f'<span class="wg-debug-toggle-label">Coaching notes <span class="wg-debug-chevron">{chevron}</span></span>',
399
+ '<span class="wg-debug-toggle-line"></span>',
400
+ '</div>',
401
+ f'<div class="wg-debug-body{collapsed_cls}">',
402
+ _streaming_debug_panels_html(state, state.selected),
403
+ '</div>',
404
+ ]
405
+
406
  parts.append('<div class="wg-rule"></div></div>')
407
  return "".join(parts)
408
 
 
486
  new_cls = " wg-coach-reply--new" if is_last else ""
487
 
488
  beckon_cls = " wg-debug-toggle--new" if is_last else ""
489
+
490
+ # ── Hero reply FIRST (above fold) ──────────────────────────────────────
491
  parts += [
492
  _mode_badge_html(result.route),
493
+ f'<div class="wg-coach-reply{new_cls}" data-alts="{alts_json}" data-alt-idx="0">',
494
+ f'<div class="wg-coach-reply-header">Your humor coach{persona_label}{another_take_btn}</div>',
495
+ f'<div class="wg-coach-reply-body">{_esc(result.selected)}</div>',
496
+ '</div>',
497
+ ]
498
+ if result.explanation:
499
+ parts.append(_explanation_panel_html(result.explanation))
500
+
501
+ # ── Drill chips (coaching follow-ups) ──────────────────────────────────
502
+ if is_last:
503
+ parts.append(
504
+ '<div class="wg-drill-chips">'
505
+ '<span class="wg-drill-chip" onclick="wgDrill(\'Make that line sharper and more cutting\')">sharpen it β†’</span>'
506
+ '<span class="wg-drill-chip" onclick="wgDrill(\'Give me a completely different angle on the same situation\')">different angle β†’</span>'
507
+ '<span class="wg-drill-chip" onclick="wgDrill(\'Explain why that line works β€” what comedy principle does it use?\')">why it works β†’</span>'
508
+ '</div>'
509
+ )
510
+
511
+ # ── Process rail SECOND (expandable coaching notes) ────────────────────
512
+ parts += [
513
  _twist_meter_html(result.metadata.twist_potential),
514
  f'<div class="wg-debug-toggle{beckon_cls}">',
515
  '<span class="wg-debug-toggle-line"></span>',
 
519
  f'<div class="wg-debug-body{collapsed_cls}">',
520
  _debug_panels_html(result),
521
  '</div>',
 
 
 
 
522
  ]
 
 
523
  parts.append('<div class="wg-rule"></div></div>')
524
  return "".join(parts)
525