Update app.py
Browse files
app.py
CHANGED
|
@@ -228,30 +228,102 @@ def simulate(prompt, selected_event, selected_persona_file, ai_mode,
|
|
| 228 |
})
|
| 229 |
state_history.append(updated_state.copy())
|
| 230 |
|
| 231 |
-
# Conversation display
|
| 232 |
conversation_display = ""
|
| 233 |
for i, turn in enumerate(conversation_history, 1):
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
if 'scenario' in turn:
|
| 236 |
-
conversation_display += f"
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
# Visualizations
|
| 242 |
state_yaml = yaml.dump(updated_state, sort_keys=False)
|
| 243 |
current_chart = plot_state(updated_state, persona['persona_name'])
|
| 244 |
history_chart = plot_interaction_history(state_history)
|
| 245 |
|
| 246 |
-
# Teaching feedback
|
| 247 |
-
teaching_feedback = f"
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
-
if
|
| 254 |
-
teaching_feedback +=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
# Log interaction
|
| 257 |
transcript_path = log_interaction(
|
|
@@ -528,7 +600,7 @@ with gr.Blocks(
|
|
| 528 |
</div>
|
| 529 |
""")
|
| 530 |
|
| 531 |
-
conversation_display = gr.
|
| 532 |
label="",
|
| 533 |
value="""
|
| 534 |
<div style='text-align: center; padding: 3rem; color: #6c757d;'>
|
|
@@ -591,7 +663,7 @@ with gr.Blocks(
|
|
| 591 |
</h3>
|
| 592 |
</div>
|
| 593 |
""")
|
| 594 |
-
teaching_output = gr.
|
| 595 |
label="",
|
| 596 |
elem_classes=["feedback-box"]
|
| 597 |
)
|
|
|
|
| 228 |
})
|
| 229 |
state_history.append(updated_state.copy())
|
| 230 |
|
| 231 |
+
# Conversation display with modern styling
|
| 232 |
conversation_display = ""
|
| 233 |
for i, turn in enumerate(conversation_history, 1):
|
| 234 |
+
# Turn number with gradient badge
|
| 235 |
+
conversation_display += f"""
|
| 236 |
+
<div style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 237 |
+
color: white; padding: 0.5rem 1rem; border-radius: 8px; display: inline-block;
|
| 238 |
+
margin-bottom: 0.5rem; font-weight: 600; font-size: 0.9rem;'>
|
| 239 |
+
Turn {i}
|
| 240 |
+
</div>\n\n"""
|
| 241 |
+
|
| 242 |
+
# Scenario context if present
|
| 243 |
if 'scenario' in turn:
|
| 244 |
+
conversation_display += f"""
|
| 245 |
+
<div style='background: #f8f9fa; border-left: 4px solid #f5576c; padding: 0.5rem 1rem;
|
| 246 |
+
margin-bottom: 1rem; border-radius: 4px; color: #495057; font-style: italic;'>
|
| 247 |
+
📖 Scene: {turn['scenario']}
|
| 248 |
+
</div>\n\n"""
|
| 249 |
+
|
| 250 |
+
# Student question with modern styling
|
| 251 |
+
conversation_display += f"""
|
| 252 |
+
<div style='background: #e8eaf6; border-radius: 12px; padding: 1rem;
|
| 253 |
+
margin-bottom: 0.8rem; border-left: 4px solid #667eea;'>
|
| 254 |
+
<div style='color: #667eea; font-weight: 700; margin-bottom: 0.3rem; font-size: 0.9rem;'>
|
| 255 |
+
👤 YOU ASKED:
|
| 256 |
+
</div>
|
| 257 |
+
<div style='color: #2d3748; font-size: 1rem; line-height: 1.5;'>
|
| 258 |
+
{turn['student']}
|
| 259 |
+
</div>
|
| 260 |
+
</div>\n\n"""
|
| 261 |
+
|
| 262 |
+
# Character response with modern styling
|
| 263 |
+
conversation_display += f"""
|
| 264 |
+
<div style='background: #fff3e0; border-radius: 12px; padding: 1rem;
|
| 265 |
+
margin-bottom: 1.5rem; border-left: 4px solid #f5576c;'>
|
| 266 |
+
<div style='color: #f5576c; font-weight: 700; margin-bottom: 0.3rem; font-size: 0.9rem;'>
|
| 267 |
+
🎭 {persona['persona_name'].upper()} REPLIED:
|
| 268 |
+
</div>
|
| 269 |
+
<div style='color: #2d3748; font-size: 1rem; line-height: 1.6;'>
|
| 270 |
+
{turn['client']}
|
| 271 |
+
</div>
|
| 272 |
+
</div>\n\n"""
|
| 273 |
+
|
| 274 |
+
conversation_display += "<hr style='border: none; border-top: 2px solid #e9ecef; margin: 1.5rem 0;'>\n\n"
|
| 275 |
|
| 276 |
# Visualizations
|
| 277 |
state_yaml = yaml.dump(updated_state, sort_keys=False)
|
| 278 |
current_chart = plot_state(updated_state, persona['persona_name'])
|
| 279 |
history_chart = plot_interaction_history(state_history)
|
| 280 |
|
| 281 |
+
# Teaching feedback - clean, educational format
|
| 282 |
+
teaching_feedback = f"""
|
| 283 |
+
<div style='background: white; border-radius: 8px; padding: 1rem; margin-bottom: 1rem;'>
|
| 284 |
+
<div style='color: #2d3748; font-size: 1rem; line-height: 1.8;'>
|
| 285 |
+
{teaching_note}
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
|
| 289 |
+
<div style='background: white; border-radius: 8px; padding: 1rem; border-left: 4px solid #667eea;'>
|
| 290 |
+
<div style='color: #667eea; font-weight: 700; font-size: 0.95rem; margin-bottom: 0.8rem;'>
|
| 291 |
+
📊 Character's Current State
|
| 292 |
+
</div>
|
| 293 |
+
<div style='color: #495057; font-size: 0.95rem; line-height: 1.6;'>
|
| 294 |
+
"""
|
| 295 |
+
|
| 296 |
+
# Add readable state descriptions
|
| 297 |
+
intensity = updated_state.get('anxiety', 0)
|
| 298 |
+
openness = updated_state.get('trust', 0)
|
| 299 |
+
candor = updated_state.get('openness', 0)
|
| 300 |
+
mode = updated_state.get('mode', 'baseline')
|
| 301 |
+
|
| 302 |
+
if intensity > 0.7:
|
| 303 |
+
teaching_feedback += " • The character is highly emotionally charged right now<br>\n"
|
| 304 |
+
elif intensity > 0.4:
|
| 305 |
+
teaching_feedback += " • The character shows moderate emotional intensity<br>\n"
|
| 306 |
+
else:
|
| 307 |
+
teaching_feedback += " • The character is relatively calm<br>\n"
|
| 308 |
|
| 309 |
+
if openness > 0.6:
|
| 310 |
+
teaching_feedback += " • They're willing to share and engage deeply<br>\n"
|
| 311 |
+
elif openness > 0.4:
|
| 312 |
+
teaching_feedback += " • They're somewhat open but still cautious<br>\n"
|
| 313 |
+
else:
|
| 314 |
+
teaching_feedback += " • They're guarded and protective<br>\n"
|
| 315 |
+
|
| 316 |
+
if mode == "trusting":
|
| 317 |
+
teaching_feedback += " • <strong>Excellent!</strong> You've built strong rapport<br>\n"
|
| 318 |
+
elif mode == "triggered":
|
| 319 |
+
teaching_feedback += " �� <strong>Note:</strong> The character feels defensive - try a gentler approach<br>\n"
|
| 320 |
+
elif mode == "decompensating":
|
| 321 |
+
teaching_feedback += " • <strong>Alert:</strong> The character is overwhelmed - consider shifting topics<br>\n"
|
| 322 |
+
|
| 323 |
+
teaching_feedback += """
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
"""
|
| 327 |
|
| 328 |
# Log interaction
|
| 329 |
transcript_path = log_interaction(
|
|
|
|
| 600 |
</div>
|
| 601 |
""")
|
| 602 |
|
| 603 |
+
conversation_display = gr.HTML(
|
| 604 |
label="",
|
| 605 |
value="""
|
| 606 |
<div style='text-align: center; padding: 3rem; color: #6c757d;'>
|
|
|
|
| 663 |
</h3>
|
| 664 |
</div>
|
| 665 |
""")
|
| 666 |
+
teaching_output = gr.HTML(
|
| 667 |
label="",
|
| 668 |
elem_classes=["feedback-box"]
|
| 669 |
)
|