Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,22 +20,12 @@ def create_app():
|
|
| 20 |
padding: 15px;
|
| 21 |
border-radius: 8px;
|
| 22 |
border: 1px solid #dee2e6;
|
| 23 |
-
color: #2c3e50;
|
| 24 |
-
}
|
| 25 |
-
.stat-card h3 {
|
| 26 |
-
color: #2c3e50;
|
| 27 |
-
margin-top: 0;
|
| 28 |
-
}
|
| 29 |
-
.stat-card p {
|
| 30 |
-
color: #495057;
|
| 31 |
-
margin: 5px 0;
|
| 32 |
}
|
| 33 |
.section-header {
|
| 34 |
font-size: 18px;
|
| 35 |
font-weight: 600;
|
| 36 |
margin-top: 20px;
|
| 37 |
margin-bottom: 10px;
|
| 38 |
-
color: #2c3e50;
|
| 39 |
}
|
| 40 |
.insight-item {
|
| 41 |
background: white;
|
|
@@ -43,10 +33,6 @@ def create_app():
|
|
| 43 |
margin: 8px 0;
|
| 44 |
border-left: 3px solid #3498db;
|
| 45 |
border-radius: 4px;
|
| 46 |
-
color: #2c3e50;
|
| 47 |
-
}
|
| 48 |
-
.insight-item strong {
|
| 49 |
-
color: #2c3e50;
|
| 50 |
}
|
| 51 |
.percentage {
|
| 52 |
color: #3498db;
|
|
@@ -425,15 +411,15 @@ def create_app():
|
|
| 425 |
def format_insight(insight):
|
| 426 |
"""Format a single insight with percentage and evidence"""
|
| 427 |
html = f"""
|
| 428 |
-
<div class="insight-item">
|
| 429 |
-
<div><strong>{insight['text']}</strong></div>
|
| 430 |
-
<div class="percentage">{insight['percentage']}% ({insight['count']} respondents)</div>
|
| 431 |
"""
|
| 432 |
|
| 433 |
if insight.get('quotes'):
|
| 434 |
html += '<div style="margin-top: 8px;">'
|
| 435 |
for quote in insight['quotes'][:2]:
|
| 436 |
-
html += f'<div class="quote">"{quote}"</div>'
|
| 437 |
html += '</div>'
|
| 438 |
|
| 439 |
html += '</div>'
|
|
@@ -443,7 +429,7 @@ def create_app():
|
|
| 443 |
try:
|
| 444 |
if not study_name:
|
| 445 |
return (
|
| 446 |
-
"<div class='stat-card'><h3>No Study Selected</h3><p>Please select a study from the dropdown.</p></div>",
|
| 447 |
"",
|
| 448 |
""
|
| 449 |
)
|
|
@@ -456,14 +442,14 @@ def create_app():
|
|
| 456 |
|
| 457 |
if not analysis:
|
| 458 |
return (
|
| 459 |
-
"<div class='stat-card'><h3>No Analysis Available</h3><p>Submit interviews for this study to generate empathy map insights.</p></div>",
|
| 460 |
"",
|
| 461 |
""
|
| 462 |
)
|
| 463 |
|
| 464 |
if 'error' in analysis:
|
| 465 |
return (
|
| 466 |
-
f"<div class='stat-card'><h3>Analysis Error</h3><p>{analysis.get('error')}</p></div>",
|
| 467 |
"",
|
| 468 |
""
|
| 469 |
)
|
|
@@ -475,11 +461,11 @@ def create_app():
|
|
| 475 |
# Stats HTML
|
| 476 |
stats_html = f"""
|
| 477 |
<div class='stat-card'>
|
| 478 |
-
<h3>Study Statistics</h3>
|
| 479 |
-
<p><strong>Study:</strong> {study_name}</p>
|
| 480 |
-
<p><strong>Total Interviews:</strong> {total_interviews}</p>
|
| 481 |
-
<p><strong>Sessions:</strong> {total_sessions}</p>
|
| 482 |
-
<p><strong>Methodology:</strong> Thematic Analysis</p>
|
| 483 |
</div>
|
| 484 |
"""
|
| 485 |
|
|
@@ -487,8 +473,8 @@ def create_app():
|
|
| 487 |
updated_at = analysis.get('updated_at', 'Unknown')
|
| 488 |
update_html = f"""
|
| 489 |
<div class='stat-card'>
|
| 490 |
-
<h3>Last Updated</h3>
|
| 491 |
-
<p>{updated_at}</p>
|
| 492 |
</div>
|
| 493 |
"""
|
| 494 |
|
|
@@ -497,49 +483,49 @@ def create_app():
|
|
| 497 |
|
| 498 |
# WHO
|
| 499 |
if 'who' in analysis:
|
| 500 |
-
analysis_html += "<div class='section-header'>WHO: Customer Segment Profile</div>"
|
| 501 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['who'].get('description', '')}</em></p>"
|
| 502 |
for insight in analysis['who'].get('insights', []):
|
| 503 |
analysis_html += format_insight(insight)
|
| 504 |
|
| 505 |
# GOAL
|
| 506 |
if 'goal' in analysis:
|
| 507 |
-
analysis_html += "<div class='section-header'>GOAL: Jobs-to-be-Done</div>"
|
| 508 |
-
analysis_html += f"<p style='color: #495057;'><strong>Main Goal:</strong> {analysis['goal'].get('main_goal', '')}</p>"
|
| 509 |
for insight in analysis['goal'].get('insights', []):
|
| 510 |
analysis_html += format_insight(insight)
|
| 511 |
|
| 512 |
# SEE
|
| 513 |
if 'see' in analysis:
|
| 514 |
-
analysis_html += "<div class='section-header'>SEE: External Observations</div>"
|
| 515 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['see'].get('summary', '')}</em></p>"
|
| 516 |
for insight in analysis['see'].get('insights', []):
|
| 517 |
analysis_html += format_insight(insight)
|
| 518 |
|
| 519 |
# SAY
|
| 520 |
if 'say' in analysis:
|
| 521 |
-
analysis_html += "<div class='section-header'>SAY: Verbal Expressions</div>"
|
| 522 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['say'].get('summary', '')}</em></p>"
|
| 523 |
for insight in analysis['say'].get('insights', []):
|
| 524 |
analysis_html += format_insight(insight)
|
| 525 |
|
| 526 |
# DO
|
| 527 |
if 'do' in analysis:
|
| 528 |
-
analysis_html += "<div class='section-header'>DO: Behaviors & Actions</div>"
|
| 529 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['do'].get('summary', '')}</em></p>"
|
| 530 |
for insight in analysis['do'].get('insights', []):
|
| 531 |
analysis_html += format_insight(insight)
|
| 532 |
|
| 533 |
# HEAR
|
| 534 |
if 'hear' in analysis:
|
| 535 |
-
analysis_html += "<div class='section-header'>HEAR: External Influences</div>"
|
| 536 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['hear'].get('summary', '')}</em></p>"
|
| 537 |
for insight in analysis['hear'].get('insights', []):
|
| 538 |
analysis_html += format_insight(insight)
|
| 539 |
|
| 540 |
# THINK & FEEL
|
| 541 |
if 'think_feel' in analysis:
|
| 542 |
-
analysis_html += "<div class='section-header'>THINK & FEEL: Internal States</div>"
|
| 543 |
|
| 544 |
analysis_html += "<h4 style='margin-top: 15px; color: #e74c3c;'>Pains (Obstacles & Frustrations)</h4>"
|
| 545 |
for pain in analysis['think_feel'].get('pains', []):
|
|
@@ -554,7 +540,7 @@ def create_app():
|
|
| 554 |
return stats_html, update_html, analysis_html
|
| 555 |
|
| 556 |
except Exception as e:
|
| 557 |
-
return f"<div class='stat-card'><h3>Error</h3><p>{str(e)}</p></div>", "", ""
|
| 558 |
|
| 559 |
# Load studies on tab open
|
| 560 |
app.load(refresh_studies, outputs=[study_dropdown])
|
|
|
|
| 20 |
padding: 15px;
|
| 21 |
border-radius: 8px;
|
| 22 |
border: 1px solid #dee2e6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
.section-header {
|
| 25 |
font-size: 18px;
|
| 26 |
font-weight: 600;
|
| 27 |
margin-top: 20px;
|
| 28 |
margin-bottom: 10px;
|
|
|
|
| 29 |
}
|
| 30 |
.insight-item {
|
| 31 |
background: white;
|
|
|
|
| 33 |
margin: 8px 0;
|
| 34 |
border-left: 3px solid #3498db;
|
| 35 |
border-radius: 4px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
.percentage {
|
| 38 |
color: #3498db;
|
|
|
|
| 411 |
def format_insight(insight):
|
| 412 |
"""Format a single insight with percentage and evidence"""
|
| 413 |
html = f"""
|
| 414 |
+
<div class="insight-item" style='background: white; padding: 12px; margin: 8px 0; border-left: 3px solid #3498db; border-radius: 4px;'>
|
| 415 |
+
<div><strong style='color: #1a1a1a;'>{insight['text']}</strong></div>
|
| 416 |
+
<div class="percentage" style='color: #3498db; font-weight: 600;'>{insight['percentage']}% ({insight['count']} respondents)</div>
|
| 417 |
"""
|
| 418 |
|
| 419 |
if insight.get('quotes'):
|
| 420 |
html += '<div style="margin-top: 8px;">'
|
| 421 |
for quote in insight['quotes'][:2]:
|
| 422 |
+
html += f'<div class="quote" style="font-style: italic; color: #6c757d; margin-left: 15px; padding: 5px 0;">"{quote}"</div>'
|
| 423 |
html += '</div>'
|
| 424 |
|
| 425 |
html += '</div>'
|
|
|
|
| 429 |
try:
|
| 430 |
if not study_name:
|
| 431 |
return (
|
| 432 |
+
"<div class='stat-card' style='color: #1a1a1a;'><h3 style='color: #1a1a1a;'>No Study Selected</h3><p style='color: #1a1a1a;'>Please select a study from the dropdown.</p></div>",
|
| 433 |
"",
|
| 434 |
""
|
| 435 |
)
|
|
|
|
| 442 |
|
| 443 |
if not analysis:
|
| 444 |
return (
|
| 445 |
+
"<div class='stat-card' style='color: #1a1a1a;'><h3 style='color: #1a1a1a;'>No Analysis Available</h3><p style='color: #1a1a1a;'>Submit interviews for this study to generate empathy map insights.</p></div>",
|
| 446 |
"",
|
| 447 |
""
|
| 448 |
)
|
| 449 |
|
| 450 |
if 'error' in analysis:
|
| 451 |
return (
|
| 452 |
+
f"<div class='stat-card' style='color: #1a1a1a;'><h3 style='color: #1a1a1a;'>Analysis Error</h3><p style='color: #1a1a1a;'>{analysis.get('error')}</p></div>",
|
| 453 |
"",
|
| 454 |
""
|
| 455 |
)
|
|
|
|
| 461 |
# Stats HTML
|
| 462 |
stats_html = f"""
|
| 463 |
<div class='stat-card'>
|
| 464 |
+
<h3 style='color: #1a1a1a; margin-top: 0;'>Study Statistics</h3>
|
| 465 |
+
<p style='color: #1a1a1a; margin: 5px 0;'><strong style='color: #1a1a1a;'>Study:</strong> {study_name}</p>
|
| 466 |
+
<p style='color: #1a1a1a; margin: 5px 0;'><strong style='color: #1a1a1a;'>Total Interviews:</strong> {total_interviews}</p>
|
| 467 |
+
<p style='color: #1a1a1a; margin: 5px 0;'><strong style='color: #1a1a1a;'>Sessions:</strong> {total_sessions}</p>
|
| 468 |
+
<p style='color: #1a1a1a; margin: 5px 0;'><strong style='color: #1a1a1a;'>Methodology:</strong> Thematic Analysis</p>
|
| 469 |
</div>
|
| 470 |
"""
|
| 471 |
|
|
|
|
| 473 |
updated_at = analysis.get('updated_at', 'Unknown')
|
| 474 |
update_html = f"""
|
| 475 |
<div class='stat-card'>
|
| 476 |
+
<h3 style='color: #1a1a1a; margin-top: 0;'>Last Updated</h3>
|
| 477 |
+
<p style='color: #1a1a1a;'>{updated_at}</p>
|
| 478 |
</div>
|
| 479 |
"""
|
| 480 |
|
|
|
|
| 483 |
|
| 484 |
# WHO
|
| 485 |
if 'who' in analysis:
|
| 486 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>WHO: Customer Segment Profile</div>"
|
| 487 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['who'].get('description', '')}</em></p>"
|
| 488 |
for insight in analysis['who'].get('insights', []):
|
| 489 |
analysis_html += format_insight(insight)
|
| 490 |
|
| 491 |
# GOAL
|
| 492 |
if 'goal' in analysis:
|
| 493 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>GOAL: Jobs-to-be-Done</div>"
|
| 494 |
+
analysis_html += f"<p style='color: #495057;'><strong style='color: #1a1a1a;'>Main Goal:</strong> {analysis['goal'].get('main_goal', '')}</p>"
|
| 495 |
for insight in analysis['goal'].get('insights', []):
|
| 496 |
analysis_html += format_insight(insight)
|
| 497 |
|
| 498 |
# SEE
|
| 499 |
if 'see' in analysis:
|
| 500 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>SEE: External Observations</div>"
|
| 501 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['see'].get('summary', '')}</em></p>"
|
| 502 |
for insight in analysis['see'].get('insights', []):
|
| 503 |
analysis_html += format_insight(insight)
|
| 504 |
|
| 505 |
# SAY
|
| 506 |
if 'say' in analysis:
|
| 507 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>SAY: Verbal Expressions</div>"
|
| 508 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['say'].get('summary', '')}</em></p>"
|
| 509 |
for insight in analysis['say'].get('insights', []):
|
| 510 |
analysis_html += format_insight(insight)
|
| 511 |
|
| 512 |
# DO
|
| 513 |
if 'do' in analysis:
|
| 514 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>DO: Behaviors & Actions</div>"
|
| 515 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['do'].get('summary', '')}</em></p>"
|
| 516 |
for insight in analysis['do'].get('insights', []):
|
| 517 |
analysis_html += format_insight(insight)
|
| 518 |
|
| 519 |
# HEAR
|
| 520 |
if 'hear' in analysis:
|
| 521 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>HEAR: External Influences</div>"
|
| 522 |
analysis_html += f"<p style='color: #495057;'><em>{analysis['hear'].get('summary', '')}</em></p>"
|
| 523 |
for insight in analysis['hear'].get('insights', []):
|
| 524 |
analysis_html += format_insight(insight)
|
| 525 |
|
| 526 |
# THINK & FEEL
|
| 527 |
if 'think_feel' in analysis:
|
| 528 |
+
analysis_html += "<div class='section-header' style='color: #1a1a1a;'>THINK & FEEL: Internal States</div>"
|
| 529 |
|
| 530 |
analysis_html += "<h4 style='margin-top: 15px; color: #e74c3c;'>Pains (Obstacles & Frustrations)</h4>"
|
| 531 |
for pain in analysis['think_feel'].get('pains', []):
|
|
|
|
| 540 |
return stats_html, update_html, analysis_html
|
| 541 |
|
| 542 |
except Exception as e:
|
| 543 |
+
return f"<div class='stat-card' style='color: #1a1a1a;'><h3 style='color: #1a1a1a;'>Error</h3><p style='color: #1a1a1a;'>{str(e)}</p></div>", "", ""
|
| 544 |
|
| 545 |
# Load studies on tab open
|
| 546 |
app.load(refresh_studies, outputs=[study_dropdown])
|