Spaces:
Running
Running
Akshay Babbar commited on
Commit ·
907b877
1
Parent(s): e4073dc
tweaked the coaching logic
Browse files- app.py +76 -55
- witgym/config.py +1 -1
- witgym/generator.py +6 -5
app.py
CHANGED
|
@@ -43,32 +43,32 @@ STARTERS = [
|
|
| 43 |
"I went to bed early last night.",
|
| 44 |
]
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
APP_CSS = """
|
| 49 |
#witgym-main { max-width: 1200px; margin: 0 auto; width: 100%; }
|
| 50 |
|
| 51 |
.witgym-header {
|
| 52 |
display: flex; flex-direction: column; align-items: center;
|
| 53 |
-
text-align: center; gap: 0.35rem; margin-bottom:
|
| 54 |
}
|
| 55 |
.witgym-logo { width: 56px; height: 56px; flex-shrink: 0; }
|
| 56 |
-
.witgym-title { font-size:
|
| 57 |
-
.witgym-tagline { color: #6b6560; margin: 0; font-size:
|
| 58 |
|
| 59 |
.wg-transcript {
|
| 60 |
-
font-
|
| 61 |
-
font-size: 15px; line-height: 1.55; color: #1a1a1a;
|
| 62 |
}
|
| 63 |
.wg-empty { color: #777; font-style: italic; padding: 1.5rem 0; text-align: center; }
|
| 64 |
.wg-turn { margin-bottom: 1.5rem; }
|
| 65 |
.wg-turn--thinking { cursor: wait; }
|
| 66 |
-
.wg-user { color: #16a34a; font-weight: 700; margin-bottom: 0.75rem; font-size:
|
| 67 |
.wg-thinking {
|
| 68 |
display: flex; align-items: center; gap: 0.5rem;
|
| 69 |
-
color: #6b6258; font-style: italic; font-size:
|
| 70 |
padding: 0.65rem 0.75rem; margin-top: 0.25rem;
|
| 71 |
-
background: #f3efe8; border-radius:
|
| 72 |
}
|
| 73 |
.wg-thinking-icon { flex-shrink: 0; animation: wg-spin 0.85s linear infinite; }
|
| 74 |
@keyframes wg-spin { to { transform: rotate(360deg); } }
|
|
@@ -84,20 +84,19 @@ APP_CSS = """
|
|
| 84 |
flex: 1; height: 1px; background: #d8d0c4;
|
| 85 |
}
|
| 86 |
.wg-coach-divider-label {
|
| 87 |
-
white-space: nowrap; font-style: italic; color: #6b6258; font-size: 0.
|
| 88 |
}
|
| 89 |
.wg-coach-reply {
|
| 90 |
margin-top: 1.1rem; padding: 0.9rem 1rem;
|
| 91 |
background: #f7f3ec; border: 1px solid #d4cbb8; border-left: 3px solid #2d6a4f;
|
| 92 |
-
border-radius:
|
| 93 |
}
|
| 94 |
.wg-coach-reply-header {
|
| 95 |
font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em;
|
| 96 |
text-transform: uppercase; color: #2d6a4f; margin-bottom: 0.45rem;
|
| 97 |
}
|
| 98 |
.wg-coach-reply-body {
|
| 99 |
-
font-
|
| 100 |
-
font-size: 1.05rem; line-height: 1.5; color: #2a2520;
|
| 101 |
}
|
| 102 |
.wg-coach-reply--compact { margin-top: 0.75rem; }
|
| 103 |
.wg-rule { border-top: 1px solid #e8e2d8; margin: 0.75rem 0; }
|
|
@@ -105,9 +104,9 @@ APP_CSS = """
|
|
| 105 |
.wg-dim-italic { color: #888; font-style: italic; }
|
| 106 |
.wg-cyan { color: #0891b2; }
|
| 107 |
.wg-bold { font-weight: 600; }
|
| 108 |
-
.wg-panel { border-radius:
|
| 109 |
-
border: 1px solid; font-size:
|
| 110 |
-
.wg-panel-title { font-weight: 700; margin-bottom: 0.35rem; font-size:
|
| 111 |
.wg-panel-yellow { background: #fffbeb; border-color: #fbbf24; color: #92400e; }
|
| 112 |
.wg-panel-yellow .wg-panel-title { color: #b45309; }
|
| 113 |
.wg-panel-blue { background: #eff6ff; border-color: #60a5fa; color: #1e3a5f; }
|
|
@@ -122,6 +121,15 @@ APP_CSS = """
|
|
| 122 |
width: 100%; text-align: left; white-space: normal;
|
| 123 |
height: auto !important; min-height: 2.25rem; line-height: 1.35;
|
| 124 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
"""
|
| 126 |
|
| 127 |
_shared = None
|
|
@@ -252,6 +260,16 @@ def _theme():
|
|
| 252 |
primary_hue=gr.themes.colors.stone,
|
| 253 |
secondary_hue=gr.themes.colors.amber,
|
| 254 |
neutral_hue=gr.themes.colors.stone,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
)
|
| 256 |
.set(
|
| 257 |
body_background_fill="#fffff8",
|
|
@@ -264,54 +282,57 @@ def _theme():
|
|
| 264 |
|
| 265 |
|
| 266 |
def build_ui():
|
| 267 |
-
with gr.Blocks(title="WitGym") as demo:
|
| 268 |
gr.HTML(_header_html())
|
| 269 |
|
| 270 |
session_state = gr.State(_new_session())
|
| 271 |
|
| 272 |
with gr.Column(elem_id="witgym-main"):
|
| 273 |
-
with gr.Row():
|
| 274 |
with gr.Column(scale=3):
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
show_label=False,
|
| 284 |
-
placeholder="Describe a situation… (Enter to send)",
|
| 285 |
-
lines=1,
|
| 286 |
-
max_lines=1,
|
| 287 |
-
)
|
| 288 |
-
with gr.Row():
|
| 289 |
-
submit_btn = gr.Button(
|
| 290 |
-
"Start Practicing Humour",
|
| 291 |
-
variant="primary",
|
| 292 |
-
scale=4,
|
| 293 |
)
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
with gr.Column(scale=1):
|
| 301 |
-
gr.
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
| 315 |
|
| 316 |
submit_btn.click(
|
| 317 |
fn=practice,
|
|
|
|
| 43 |
"I went to bed early last night.",
|
| 44 |
]
|
| 45 |
|
| 46 |
+
TRANSCRIPT_MIN_HEIGHT = 420
|
| 47 |
+
TRANSCRIPT_MAX_HEIGHT = 560
|
| 48 |
|
| 49 |
APP_CSS = """
|
| 50 |
#witgym-main { max-width: 1200px; margin: 0 auto; width: 100%; }
|
| 51 |
|
| 52 |
.witgym-header {
|
| 53 |
display: flex; flex-direction: column; align-items: center;
|
| 54 |
+
text-align: center; gap: 0.35rem; margin-bottom: 0.75rem;
|
| 55 |
}
|
| 56 |
.witgym-logo { width: 56px; height: 56px; flex-shrink: 0; }
|
| 57 |
+
.witgym-title { font-size: 2.15rem; font-weight: 700; margin: 0; color: #3d3429; }
|
| 58 |
+
.witgym-tagline { color: #6b6560; margin: 0; font-size: 1.05rem; }
|
| 59 |
|
| 60 |
.wg-transcript {
|
| 61 |
+
font-size: 17px; line-height: 1.6; color: #1a1a1a;
|
|
|
|
| 62 |
}
|
| 63 |
.wg-empty { color: #777; font-style: italic; padding: 1.5rem 0; text-align: center; }
|
| 64 |
.wg-turn { margin-bottom: 1.5rem; }
|
| 65 |
.wg-turn--thinking { cursor: wait; }
|
| 66 |
+
.wg-user { color: #16a34a; font-weight: 700; margin-bottom: 0.75rem; font-size: 18px; }
|
| 67 |
.wg-thinking {
|
| 68 |
display: flex; align-items: center; gap: 0.5rem;
|
| 69 |
+
color: #6b6258; font-style: italic; font-size: 1.05rem;
|
| 70 |
padding: 0.65rem 0.75rem; margin-top: 0.25rem;
|
| 71 |
+
background: #f3efe8; border-radius: 10px; border: 1px solid #e0d8cc;
|
| 72 |
}
|
| 73 |
.wg-thinking-icon { flex-shrink: 0; animation: wg-spin 0.85s linear infinite; }
|
| 74 |
@keyframes wg-spin { to { transform: rotate(360deg); } }
|
|
|
|
| 84 |
flex: 1; height: 1px; background: #d8d0c4;
|
| 85 |
}
|
| 86 |
.wg-coach-divider-label {
|
| 87 |
+
white-space: nowrap; font-style: italic; color: #6b6258; font-size: 0.92rem; font-weight: 600;
|
| 88 |
}
|
| 89 |
.wg-coach-reply {
|
| 90 |
margin-top: 1.1rem; padding: 0.9rem 1rem;
|
| 91 |
background: #f7f3ec; border: 1px solid #d4cbb8; border-left: 3px solid #2d6a4f;
|
| 92 |
+
border-radius: 12px;
|
| 93 |
}
|
| 94 |
.wg-coach-reply-header {
|
| 95 |
font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em;
|
| 96 |
text-transform: uppercase; color: #2d6a4f; margin-bottom: 0.45rem;
|
| 97 |
}
|
| 98 |
.wg-coach-reply-body {
|
| 99 |
+
font-size: 1.15rem; line-height: 1.55; color: #2a2520;
|
|
|
|
| 100 |
}
|
| 101 |
.wg-coach-reply--compact { margin-top: 0.75rem; }
|
| 102 |
.wg-rule { border-top: 1px solid #e8e2d8; margin: 0.75rem 0; }
|
|
|
|
| 104 |
.wg-dim-italic { color: #888; font-style: italic; }
|
| 105 |
.wg-cyan { color: #0891b2; }
|
| 106 |
.wg-bold { font-weight: 600; }
|
| 107 |
+
.wg-panel { border-radius: 10px; padding: 0.65rem 0.85rem; margin: 0.5rem 0;
|
| 108 |
+
border: 1px solid; font-size: 15px; }
|
| 109 |
+
.wg-panel-title { font-weight: 700; margin-bottom: 0.35rem; font-size: 14px; }
|
| 110 |
.wg-panel-yellow { background: #fffbeb; border-color: #fbbf24; color: #92400e; }
|
| 111 |
.wg-panel-yellow .wg-panel-title { color: #b45309; }
|
| 112 |
.wg-panel-blue { background: #eff6ff; border-color: #60a5fa; color: #1e3a5f; }
|
|
|
|
| 121 |
width: 100%; text-align: left; white-space: normal;
|
| 122 |
height: auto !important; min-height: 2.25rem; line-height: 1.35;
|
| 123 |
}
|
| 124 |
+
|
| 125 |
+
#wg-chat-shell,
|
| 126 |
+
#wg-starters-shell {
|
| 127 |
+
border: 1px solid rgba(216, 212, 200, 0.95);
|
| 128 |
+
background: rgba(250, 249, 246, 0.88);
|
| 129 |
+
border-radius: 14px;
|
| 130 |
+
overflow: hidden;
|
| 131 |
+
box-shadow: 0 1px 4px rgba(61, 52, 41, 0.06);
|
| 132 |
+
}
|
| 133 |
"""
|
| 134 |
|
| 135 |
_shared = None
|
|
|
|
| 260 |
primary_hue=gr.themes.colors.stone,
|
| 261 |
secondary_hue=gr.themes.colors.amber,
|
| 262 |
neutral_hue=gr.themes.colors.stone,
|
| 263 |
+
text_size=gr.themes.sizes.text_lg,
|
| 264 |
+
radius_size=gr.themes.sizes.radius_lg,
|
| 265 |
+
font=(
|
| 266 |
+
"Aptos",
|
| 267 |
+
gr.themes.GoogleFont("EB Garamond"),
|
| 268 |
+
"Garamond",
|
| 269 |
+
"Georgia",
|
| 270 |
+
"Times New Roman",
|
| 271 |
+
"serif",
|
| 272 |
+
),
|
| 273 |
)
|
| 274 |
.set(
|
| 275 |
body_background_fill="#fffff8",
|
|
|
|
| 282 |
|
| 283 |
|
| 284 |
def build_ui():
|
| 285 |
+
with gr.Blocks(title="WitGym", fill_height=True) as demo:
|
| 286 |
gr.HTML(_header_html())
|
| 287 |
|
| 288 |
session_state = gr.State(_new_session())
|
| 289 |
|
| 290 |
with gr.Column(elem_id="witgym-main"):
|
| 291 |
+
with gr.Row(equal_height=True):
|
| 292 |
with gr.Column(scale=3):
|
| 293 |
+
with gr.Group(elem_id="wg-chat-shell"):
|
| 294 |
+
transcript = gr.HTML(
|
| 295 |
+
value=format_transcript_html([]),
|
| 296 |
+
min_height=TRANSCRIPT_MIN_HEIGHT,
|
| 297 |
+
max_height=TRANSCRIPT_MAX_HEIGHT,
|
| 298 |
+
autoscroll=True,
|
| 299 |
+
show_label=False,
|
| 300 |
+
padding=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
)
|
| 302 |
+
user_input = gr.Textbox(
|
| 303 |
+
show_label=False,
|
| 304 |
+
placeholder="Describe a situation… (Enter to send)",
|
| 305 |
+
lines=1,
|
| 306 |
+
max_lines=1,
|
| 307 |
)
|
| 308 |
+
with gr.Row():
|
| 309 |
+
submit_btn = gr.Button(
|
| 310 |
+
"Start Practicing Humour",
|
| 311 |
+
variant="primary",
|
| 312 |
+
scale=4,
|
| 313 |
+
)
|
| 314 |
+
clear_btn = gr.Button(
|
| 315 |
+
"Clear conversation",
|
| 316 |
+
size="sm",
|
| 317 |
+
variant="secondary",
|
| 318 |
+
scale=1,
|
| 319 |
+
)
|
| 320 |
with gr.Column(scale=1):
|
| 321 |
+
with gr.Group(elem_id="wg-starters-shell"):
|
| 322 |
+
gr.Markdown("**Try a starter**")
|
| 323 |
+
for text in STARTERS:
|
| 324 |
+
starter_btn = gr.Button(
|
| 325 |
+
text,
|
| 326 |
+
size="sm",
|
| 327 |
+
variant="secondary",
|
| 328 |
+
elem_classes=["wg-starter-btn"],
|
| 329 |
+
)
|
| 330 |
+
starter_btn.click(
|
| 331 |
+
fn=fill_starter,
|
| 332 |
+
inputs=[gr.State(text)],
|
| 333 |
+
outputs=user_input,
|
| 334 |
+
queue=False,
|
| 335 |
+
)
|
| 336 |
|
| 337 |
submit_btn.click(
|
| 338 |
fn=practice,
|
witgym/config.py
CHANGED
|
@@ -21,7 +21,7 @@ DTYPE = torch.bfloat16
|
|
| 21 |
# Sampling
|
| 22 |
EXTRACT_TEMP = 0.2
|
| 23 |
EXTRACT_DO_SAMPLE = False
|
| 24 |
-
GENERATE_TEMP = 1.
|
| 25 |
GENERATE_MIN_P = 0.06
|
| 26 |
GENERATE_MAX_NEW_TOKENS = 40
|
| 27 |
RANK_TEMP = 0.1
|
|
|
|
| 21 |
# Sampling
|
| 22 |
EXTRACT_TEMP = 0.2
|
| 23 |
EXTRACT_DO_SAMPLE = False
|
| 24 |
+
GENERATE_TEMP = 1.0 # slightly lower to reduce arbitrary domain invention
|
| 25 |
GENERATE_MIN_P = 0.06
|
| 26 |
GENERATE_MAX_NEW_TOKENS = 40
|
| 27 |
RANK_TEMP = 0.1
|
witgym/generator.py
CHANGED
|
@@ -21,7 +21,8 @@ PERSONA_INSTRUCTIONS = {
|
|
| 21 |
"What is it protecting? What does it cost? State it precisely.\n"
|
| 22 |
" PATH B (subtext contains status claim or competence assertion): "
|
| 23 |
"State the actual outcome as if it has already become concrete. Past tense. "
|
| 24 |
-
"One specific image or action anchored in the user's situation.
|
|
|
|
| 25 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
| 26 |
"You've seen this exact rationalization a hundred times. "
|
| 27 |
"You're not angry — you're just tired. "
|
|
@@ -41,9 +42,8 @@ PERSONA_INSTRUCTIONS = {
|
|
| 41 |
"Follow the anxiety's own internal logic to its physical inevitable endpoint. "
|
| 42 |
"Name the specific form: a concrete image, measurable action, or physical object "
|
| 43 |
"from the user's situation.\n"
|
| 44 |
-
" PATH B (connector field is non-null
|
| 45 |
-
"
|
| 46 |
-
"reveals the identical human truth. Deliver from that domain without naming the parallel.\n"
|
| 47 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
| 48 |
"You're the only person in the room who sees where this logically ends. "
|
| 49 |
"You're not being weird — you're just following the math. "
|
|
@@ -56,7 +56,7 @@ PERSONA_INSTRUCTIONS = {
|
|
| 56 |
"Your punchline must land on the second meaning of the connector word. "
|
| 57 |
"The setup's expected reading of that word is the straight path. You take the other one.\n"
|
| 58 |
" PATH B (connector is null): "
|
| 59 |
-
"Apply the dominant verb from the subtext to the most structurally incongruous object from daily life. "
|
| 60 |
"Deliver from inside that object's world, as if you've been there all along. "
|
| 61 |
"Do not name the parallel. Do not explain the connection.\n"
|
| 62 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
|
@@ -99,6 +99,7 @@ CONSTRAINTS (ALL must be satisfied):
|
|
| 99 |
10. If any phrase from the precedent block appears in your line, rewrite it — use the mechanism only, never the precedent's wording.
|
| 100 |
11. DOMAIN ANCHOR — Do not introduce institutions, departments, legal process, or workplace nouns unless already implied by surface, subtext, or power_dynamic. Prefer nouns from the user input.
|
| 101 |
12. Treat unexpected domain shifts (HR, litigation, supply chain, middle-manager hierarchy) as defects unless the input already implies them.
|
|
|
|
| 102 |
|
| 103 |
CONVERSATION CONTEXT (last turns, for callbacks):
|
| 104 |
{context_str}
|
|
|
|
| 21 |
"What is it protecting? What does it cost? State it precisely.\n"
|
| 22 |
" PATH B (subtext contains status claim or competence assertion): "
|
| 23 |
"State the actual outcome as if it has already become concrete. Past tense. "
|
| 24 |
+
"One specific image or action anchored in the user's situation. "
|
| 25 |
+
"Reuse nouns/verbs from surface or subtext. Do NOT import a new setting, industry, or object.\n"
|
| 26 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
| 27 |
"You've seen this exact rationalization a hundred times. "
|
| 28 |
"You're not angry — you're just tired. "
|
|
|
|
| 42 |
"Follow the anxiety's own internal logic to its physical inevitable endpoint. "
|
| 43 |
"Name the specific form: a concrete image, measurable action, or physical object "
|
| 44 |
"from the user's situation.\n"
|
| 45 |
+
" PATH B (connector field is non-null): "
|
| 46 |
+
"Land on the second meaning of the connector word, but keep the setting and nouns inside the user's situation.\n"
|
|
|
|
| 47 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
| 48 |
"You're the only person in the room who sees where this logically ends. "
|
| 49 |
"You're not being weird — you're just following the math. "
|
|
|
|
| 56 |
"Your punchline must land on the second meaning of the connector word. "
|
| 57 |
"The setup's expected reading of that word is the straight path. You take the other one.\n"
|
| 58 |
" PATH B (connector is null): "
|
| 59 |
+
"Apply the dominant verb from the subtext (use the exact verb/action) to the most structurally incongruous object from daily life. "
|
| 60 |
"Deliver from inside that object's world, as if you've been there all along. "
|
| 61 |
"Do not name the parallel. Do not explain the connection.\n"
|
| 62 |
"You pick the path silently. Output only the wit line — never the path label.\n\n"
|
|
|
|
| 99 |
10. If any phrase from the precedent block appears in your line, rewrite it — use the mechanism only, never the precedent's wording.
|
| 100 |
11. DOMAIN ANCHOR — Do not introduce institutions, departments, legal process, or workplace nouns unless already implied by surface, subtext, or power_dynamic. Prefer nouns from the user input.
|
| 101 |
12. Treat unexpected domain shifts (HR, litigation, supply chain, middle-manager hierarchy) as defects unless the input already implies them.
|
| 102 |
+
13. CROSS-DOMAIN PIVOT — Only BISOCIATE may introduce a new domain/object. If persona is not BISOCIATE, stay inside the user's world. If BISOCIATE pivots domains, the pivot must be discoverable from a verb/action explicitly present in the subtext or from the connector’s second meaning; otherwise rewrite.
|
| 103 |
|
| 104 |
CONVERSATION CONTEXT (last turns, for callbacks):
|
| 105 |
{context_str}
|