Spaces:
Runtime error
Runtime error
File size: 22,678 Bytes
df96526 bcb31b6 fc3c31c 5366321 fc3c31c 4323dbe fc9aca5 ed56fc7 916b905 ed56fc7 4323dbe fc9aca5 ed56fc7 4323dbe fc9aca5 ed56fc7 fc9aca5 ed56fc7 12ef42b fc9aca5 90144f5 ec931d5 12ef42b ed56fc7 12ef42b ed56fc7 12ef42b e886e8e ed56fc7 fc9aca5 12ef42b fc9aca5 12ef42b c752ca6 9ced56c c752ca6 c02843f c752ca6 1287ca0 c02843f 7b8a2ed c02843f 7b8a2ed c02843f 7b8a2ed bcb31b6 7b8a2ed bcb31b6 7b8a2ed bcb31b6 7b8a2ed bcb31b6 7b8a2ed bcb31b6 c02843f bcb31b6 c752ca6 fc9aca5 9ced56c fc9aca5 4323dbe 864fa7f ed56fc7 fc3c31c ed56fc7 fc9aca5 4323dbe 1287ca0 4323dbe fc9aca5 c752ca6 864fa7f 4323dbe 864fa7f c752ca6 9ced56c c752ca6 864fa7f fc9aca5 1287ca0 7b8a2ed bcb31b6 7b8a2ed bcb31b6 1287ca0 4323dbe 864fa7f ed56fc7 c752ca6 864fa7f ed56fc7 1287ca0 fc3c31c 916b905 c752ca6 916b905 4323dbe 916b905 864fa7f c752ca6 864fa7f bcb31b6 916b905 1287ca0 fc9aca5 1287ca0 ed56fc7 1287ca0 864fa7f fc9aca5 bcb31b6 50c4a5c bcb31b6 fc9aca5 ed56fc7 fc9aca5 ed56fc7 fc9aca5 9ced56c bcb31b6 9ced56c fc9aca5 ed56fc7 9ced56c ed56fc7 9ced56c ed56fc7 fc9aca5 9ced56c c080422 9ced56c fc9aca5 ed56fc7 fc9aca5 9ced56c fc9aca5 ed56fc7 fc9aca5 bcb31b6 9ced56c fc9aca5 ed56fc7 fc9aca5 bcb31b6 9ced56c bcb31b6 fc9aca5 ed56fc7 fc9aca5 bcb31b6 1287ca0 05dd6b6 bcb31b6 fc9aca5 ed56fc7 9ced56c fc9aca5 ed56fc7 fc9aca5 9ced56c bcb31b6 1287ca0 05dd6b6 bcb31b6 05dd6b6 bcb31b6 b0fe1bd 7b8a2ed 1287ca0 05dd6b6 7b8a2ed b0fe1bd 50c4a5c bcb31b6 50c4a5c a8e1e48 bcb31b6 50c4a5c bcb31b6 a8e1e48 bcb31b6 a8e1e48 bcb31b6 50c4a5c bcb31b6 50c4a5c bcb31b6 50c4a5c bcb31b6 fc9aca5 9ced56c fc9aca5 ed56fc7 9ced56c fc9aca5 bcb31b6 9ced56c fc9aca5 4323dbe fc9aca5 bcb31b6 fc9aca5 ed56fc7 9ced56c bcb31b6 9ced56c ed56fc7 12ef42b ed56fc7 bcb31b6 5366321 4afe112 5738f8b 2a90b55 5366321 d855377 2a90b55 5738f8b 2a90b55 5738f8b 2a90b55 5738f8b bcb31b6 2a90b55 bcb31b6 ed56fc7 9ced56c ed56fc7 916b905 1287ca0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | import os
import re
import gradio as gr
import numpy as np
import colorsys
from huggingface_hub import InferenceClient
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
# ----------------------------
# Hugging Face API Client
# ----------------------------
token = os.getenv("naiyya")
client = InferenceClient(
"Qwen/Qwen2.5-7B-Instruct",
token=token
)
# ----------------------------
# Load Embedding Model
# ----------------------------
embedding_model = SentenceTransformer(
"sentence-transformers/all-MiniLM-L6-v2"
)
# ----------------------------
# Load Knowledge Base
# ----------------------------
chunks = []
chunk_embeddings = None
try:
if os.path.exists("knowledge.txt"):
with open("knowledge.txt", "r", encoding="utf-8") as file:
knowledge_base = file.read()
chunks = [
chunk.strip()
for chunk in knowledge_base.split("\n\n")
if chunk.strip()
]
if chunks:
print(f"Loaded {len(chunks)} knowledge chunks.")
chunk_embeddings = embedding_model.encode(chunks)
else:
print("knowledge.txt exists, but no chunks were found.")
else:
print("Warning: knowledge.txt missing. Starting in pure chat mode.")
except Exception as e:
print("Knowledge base initialization error:", e)
chunks = []
chunk_embeddings = None
# ----------------------------
# Clean Model Response
# ----------------------------
def clean_response_text(content):
if content is None:
return ""
if isinstance(content, list):
text_parts = []
for item in content:
if isinstance(item, dict):
if "text" in item:
text_parts.append(str(item["text"]))
elif "content" in item:
text_parts.append(str(item["content"]))
else:
text_parts.append(str(item))
else:
text_parts.append(str(item))
text = "\n".join(text_parts)
elif isinstance(content, dict):
if "text" in content:
text = str(content["text"])
elif "content" in content:
text = str(content["content"])
else:
text = str(content)
else:
text = str(content)
# Remove weird markdown/table/code characters
text = text.replace("```", "")
text = text.replace("`", "")
text = text.replace("|", "")
text = text.replace("โ", "")
text = text.replace("โ", "")
text = text.replace("โ", "")
text = text.replace(">", "")
cleaned_lines = []
for line in text.splitlines():
line = line.strip()
if not line:
continue
cleaned_lines.append(line)
text = "\n".join(cleaned_lines)
# Clean extra spaces and extra line breaks
text = re.sub(r"\n{3,}", "\n\n", text)
text = re.sub(r"[ \t]+", " ", text)
return text.strip()
# ----------------------------
# RAG Semantic Search Function
# ----------------------------
def retrieve_context(query, top_k=3):
if not chunks or chunk_embeddings is None:
return ""
query_embedding = embedding_model.encode([query])
scores = cosine_similarity(
query_embedding,
chunk_embeddings
)[0]
top_indices = scores.argsort()[-top_k:][::-1]
relevant_chunks = [
chunks[i]
for i in top_indices
]
return "\n\n".join(relevant_chunks)
# ----------------------------
# Chat Function
# ----------------------------
def respond(message, history):
if history is None:
history = []
if not message or not message.strip():
return "", history
context = retrieve_context(message)
system_prompt = f"""
You are GlowGuide, an empathetic, non-judgmental AI Health and Emotional Well-being Assistant.
KNOWLEDGE BASE:
{context}
Your goal is to support the user's emotional well-being, confidence, healthy habits, and daily decision-making.
You can help with:
- Stress, anxiety, overwhelm, and emotional check-ins
- Social pressure, peer pressure, family expectations, school stress, work stress, and boundaries
- Coping strategies such as journaling, grounding, breathing, reframing, and mindfulness
- Healthy food ideas, balanced meals, high-protein meals, and healthier sweet snack options
- General wellness habits like sleep, movement, hydration, and routine-building
STRICT RULES:
1. EMOTIONAL SUPPORT
- Identify the user's feelings.
- Validate them warmly.
- Avoid sounding robotic or clinical.
2. SOCIAL PRESSURE
- Help users handle peer pressure, family pressure, school stress, work stress, social media comparison, or body-image pressure.
- Give practical scripts for setting boundaries when helpful.
3. FOOD, FITNESS, AND WEIGHT-RELATED SUPPORT
- Give balanced, realistic food suggestions.
- If the user asks for something sweet but healthy, suggest options like Greek yogurt bowls, fruit with nut butter, protein smoothies, dark chocolate with fruit, cottage cheese with fruit, or homemade protein snacks.
- If the user asks for high-protein meals, suggest simple meals with lean protein, carbs, and healthy fats.
- Do not promote crash dieting, starvation, extreme restriction, guilt around food, or unsafe weight loss.
- Do not diagnose eating disorders or give medical nutrition plans.
- Encourage balance, energy, strength, and feeling good rather than shame or perfection.
4. ACTIONABLE SOLUTIONS
- Give 2-4 practical suggestions.
- Make advice easy to try today.
- Keep responses concise and useful.
5. SAFETY
- You are not a doctor, therapist, dietitian, or emergency service.
- If the user mentions self-harm, suicide, severe distress, or immediate danger, encourage them to contact emergency services, a crisis hotline, or a trusted adult immediately.
6. RESPONSE FORMAT
- Begin with one warm validating sentence.
- Use normal plain text only.
- Use simple dash bullets if needed.
- Do not use vertical bars.
- Do not use the | character.
- Do not use blockquotes.
- Do not use code blocks.
- Do not use Markdown tables.
- Do not add decorative lines before or after the response.
- Do not output JSON, Python lists, dictionaries, brackets, or raw object formatting.
- Keep language simple, supportive, and encouraging.
"""
messages = [
{
"role": "system",
"content": system_prompt
}
]
for turn in history:
if isinstance(turn, dict):
role = turn.get("role")
content = clean_response_text(turn.get("content"))
if role in ["user", "assistant"] and content:
messages.append({
"role": role,
"content": content
})
messages.append({
"role": "user",
"content": message
})
try:
response = client.chat.completions.create(
model="Qwen/Qwen2.5-7B-Instruct",
messages=messages,
max_tokens=350,
temperature=0.7,
stream=False
)
raw_content = response.choices[0].message.content
reply = clean_response_text(raw_content)
# Final extra cleanup
reply = reply.replace("|", "")
reply = reply.replace("โ", "")
reply = reply.replace("โ", "")
reply = reply.replace("โ", "")
reply = reply.replace("```", "")
reply = reply.replace("`", "")
reply = reply.strip()
except Exception as e:
reply = f"Error communicating with AI: {str(e)}"
history.append({
"role": "user",
"content": message
})
history.append({
"role": "assistant",
"content": reply
})
return "", history
# ----------------------------
# Helper Functions for Tabs
# ----------------------------
def save_journal(entry, mood):
if not entry or not entry.strip():
return "Write something first, even just one sentence ๐"
if not mood:
mood = "Not selected"
return f"""
### Journal Saved Reflection ๐
**Mood:** {mood}
**Your reflection:** {entry}
**Gentle reminder:** You took a moment to check in with yourself, and that matters.
"""
def grounding_response(choice):
if choice == "5-4-3-2-1 Grounding":
return """
### 5-4-3-2-1 Grounding Exercise ๐ฟ
Name:
- 5 things you can see
- 4 things you can feel
- 3 things you can hear
- 2 things you can smell
- 1 thing you can taste
Take one slow breath after each step.
"""
if choice == "Box Breathing":
return """
### Box Breathing ๐ฌ๏ธ
Try this for 1 minute:
- Breathe in for 4 seconds
- Hold for 4 seconds
- Breathe out for 4 seconds
- Hold for 4 seconds
Repeat until your body feels a little calmer.
"""
return """
### Quick Reset โจ
Try this:
- Put both feet on the floor
- Relax your shoulders
- Take 3 slow breaths
- Say: โI am safe in this moment.โ
"""
def fuel_response(goal):
if goal == "Sweet but Healthy":
return """
### Sweet but Healthy Ideas ๐
- Greek yogurt with berries and honey
- Apple slices with peanut butter
- Protein smoothie with banana and milk
- Cottage cheese with pineapple
- Dark chocolate with strawberries
- Rice cake with peanut butter and banana
Try to choose something that gives you energy and makes you feel good.
"""
if goal == "High Protein Meal":
return """
### High-Protein Meal Ideas ๐ช
- Chicken, rice, and avocado bowl
- Turkey wrap with fruit on the side
- Eggs with toast and berries
- Greek yogurt bowl with granola and fruit
- Tuna sandwich with a side salad
- Tofu or chicken stir-fry with rice
A balanced plate usually has protein, carbs, fats, and fiber.
"""
if goal == "Quick Snack":
return """
### Quick Balanced Snacks โก
- String cheese with fruit
- Greek yogurt cup
- Protein bar
- Peanut butter toast
- Cottage cheese with fruit
- Trail mix
- Turkey roll-ups
Pick something easy, satisfying, and realistic.
"""
return """
### Balanced Wellness Tip ๐ฑ
Focus on food that gives you energy, helps you feel full, and supports your day. Balance matters more than perfection.
"""
# ----------------------------
# Custom CSS
# ----------------------------
custom_css = """
:root {
color-scheme: light !important;
}
body, .gradio-container, .contain, .main {
background: linear-gradient(135deg, #F4ECFF 0%, #EEF5FF 50%, #FFF0F4 100%) !important;
font-family: Arial, Helvetica, sans-serif !important;
color: #4A3E65 !important;
}
footer {
display: none !important;
}
.gradio-container {
max-width: 1100px !important;
margin: auto !important;
}
.app-header {
text-align: center;
padding: 22px 10px 26px 10px;
}
.app-header h1 {
color: #8E7AB5 !important;
font-size: 42px !important;
font-weight: 800 !important;
margin-bottom: 4px !important;
letter-spacing: -1px;
}
.app-header p {
color: #9F8DCA !important;
font-size: 18px !important;
font-weight: 600 !important;
}
.glow-card {
background: rgba(255, 255, 255, 0.96) !important;
border-radius: 28px !important;
border: 1px solid #EFE7FF !important;
padding: 24px !important;
box-shadow: 0px 12px 35px rgba(154, 126, 185, 0.13) !important;
margin-bottom: 24px !important;
}
.card-title {
color: #4E3B67 !important;
font-weight: 800 !important;
font-size: 22px !important;
margin-bottom: 6px !important;
}
.card-subtitle {
color: #7A6C99 !important;
font-size: 16px !important;
font-weight: 600 !important;
margin-bottom: 18px !important;
}
/* Better global text */
label,
span,
p,
h1,
h2,
h3,
h4,
li,
div {
font-family: Arial, Helvetica, sans-serif !important;
}
label,
.label-wrap,
.block-info,
.form label,
.wrap label {
color: #4E3B67 !important;
font-weight: 700 !important;
font-size: 16px !important;
}
.markdown,
.markdown *,
.prose,
.prose * {
color: #4A3E65 !important;
font-family: Arial, Helvetica, sans-serif !important;
}
.tab-nav button,
.tabitem,
[role="tab"] {
color: #5F4B7A !important;
font-weight: 800 !important;
font-size: 15px !important;
}
.mood-btn {
background: #FFF0F5 !important;
border: 1px solid #FFDDE8 !important;
border-radius: 18px !important;
padding: 14px 16px !important;
color: #7A5C86 !important;
font-weight: 800 !important;
font-size: 16px !important;
}
.mood-btn:hover {
transform: translateY(-3px);
background: #FFE5EF !important;
box-shadow: 0px 6px 14px rgba(255, 182, 193, 0.35) !important;
}
fieldset,
fieldset *,
.radio-group *,
.checkbox-group *,
select,
option {
color: #4A3E65 !important;
font-family: Arial, Helvetica, sans-serif !important;
font-weight: 600 !important;
}
input,
textarea,
select {
background: #FFFFFF !important;
color: #4A3E65 !important;
border-radius: 16px !important;
border: 1px solid #D8CDEA !important;
font-family: Arial, Helvetica, sans-serif !important;
font-size: 16px !important;
}
textarea::placeholder,
input::placeholder {
color: #7A6C99 !important;
opacity: 1 !important;
}
button {
font-family: Arial, Helvetica, sans-serif !important;
font-weight: 700 !important;
}
/* Chatbot readability & Pink Panel Adjustments */
#glow-chatbot {
background: #FFF0F5 !important; /* This sets the main chat container background pink */
color: #4A3E65 !important;
border-radius: 24px !important;
border: 1px solid #FFD6E8 !important;
padding: 12px !important;
}
#glow-chatbot .message,
#glow-chatbot *,
#glow-chatbot .prose,
#glow-chatbot .prose *,
#glow-chatbot p,
#glow-chatbot span,
#glow-chatbot div {
color: #4A3E65 !important;
font-weight: 500 !important;
font-family: Arial, Helvetica, sans-serif !important;
}
/* Individual message boxes are transparent so the panel's pink shines through */
#glow-chatbot [data-testid="user"],
#glow-chatbot [data-testid="bot"],
#glow-chatbot [data-testid="assistant"],
#glow-chatbot .message {
background: transparent !important;
border: none !important;
box-shadow: none !important;
}
/* Slightly darken user messages or distinct rows for minimal text readability separation */
#glow-chatbot .user {
background: rgba(255, 255, 255, 0.4) !important;
border-radius: 14px !important;
padding: 8px 12px !important;
}
#glow-chatbot blockquote,
#glow-chatbot pre,
#glow-chatbot code,
#glow-chatbot .prose blockquote,
#glow-chatbot .message blockquote {
border-left: none !important;
border-right: none !important;
border: none !important;
background: transparent !important;
padding-left: 0 !important;
margin-left: 0 !important;
box-shadow: none !important;
}
#glow-chatbot button {
color: #F9FAFB !important;
}
/* Dock cards */
.dock-card {
background: #F7FBFF !important;
border: 1px solid #DDEEFF !important;
border-radius: 22px !important;
padding: 22px !important;
text-align: center !important;
color: #5F4B7A !important;
box-shadow: 0px 6px 18px rgba(160, 180, 220, 0.12) !important;
}
.dock-card h3 {
color: #4E3B67 !important;
font-size: 18px !important;
font-weight: 800 !important;
margin-bottom: 8px !important;
}
.dock-card p {
color: #7B6E93 !important;
font-size: 14px !important;
margin: 6px 0 !important;
}
.footer-text {
text-align: center;
color: #7A6C99 !important;
font-size: 16px !important;
margin-top: 18px !important;
font-weight: 700 !important;
}
"""
# ----------------------------
# Gradio App With Tabs
# ----------------------------
with gr.Blocks(
title="GlowGuide",
theme=gr.themes.Soft(
primary_hue="purple",
secondary_hue="pink",
neutral_hue="slate"
)
) as demo:
gr.HTML("""
<div class="app-header">
<h1>โจ GlowGuide โจ</h1>
<p>Your light. Your pace. You matter. ๐</p>
</div>
""")
with gr.Tabs():
# Chat Tab
with gr.Tab("๐ฌ Chat"):
with gr.Column(elem_classes=["glow-card"]):
gr.HTML("""
<p class="card-title">Daily Check-in Moodboard โจ</p>
<p class="card-subtitle">How are you feeling today?</p>
""")
with gr.Row():
gr.Button("โ๏ธ Calm", elem_classes=["mood-btn"])
gr.Button("๐ธ Happy", elem_classes=["mood-btn"])
gr.Button("โ๏ธ Okay", elem_classes=["mood-btn"])
gr.Button("๐ง๏ธ Anxious", elem_classes=["mood-btn"])
gr.Button("โ๏ธ Overwhelmed", elem_classes=["mood-btn"])
gr.HTML("""
<p style="text-align:center; font-size:14px; color:#A396C7; margin-top:10px;">
๐ All feelings are valid here.
</p>
""")
with gr.Column(elem_classes=["glow-card"]):
chatbot = gr.Chatbot(
height=350,
show_label=False,
render_markdown=False,
elem_id="glow-chatbot"
)
with gr.Row():
msg_input = gr.Textbox(
placeholder="What's on your mind?",
show_label=False,
scale=9
)
submit_btn = gr.Button("โก๏ธ", scale=1)
msg_input.submit(
fn=respond,
inputs=[msg_input, chatbot],
outputs=[msg_input, chatbot]
)
submit_btn.click(
fn=respond,
inputs=[msg_input, chatbot],
outputs=[msg_input, chatbot]
)
# Journal Tab
with gr.Tab("๐ Journal"):
with gr.Column(elem_classes=["glow-card"]):
gr.HTML("""
<p class="card-title">๐ Personalized Journal</p>
<p class="card-subtitle">Write. Reflect. Heal.</p>
""")
mood_dropdown = gr.Dropdown(
choices=["Calm", "Happy", "Okay", "Anxious", "Overwhelmed"],
label="How are you feeling?"
)
journal_entry = gr.Textbox(
label="Journal Entry",
placeholder="Today I feel...",
lines=8
)
journal_btn = gr.Button("Save Reflection ๐")
journal_output = gr.Markdown()
journal_btn.click(
fn=save_journal,
inputs=[journal_entry, mood_dropdown],
outputs=journal_output
)
# Grounding Tab
with gr.Tab("๐ฎ Grounding"):
with gr.Column(elem_classes=["glow-card"]):
gr.HTML("""
<p class="card-title">๐ฎ Grounding Games</p>
<p class="card-subtitle">Play. Breathe. Reset.</p>
""")
grounding_choice = gr.Radio(
choices=[
"5-4-3-2-1 Grounding",
"Box Breathing",
"Quick Reset"
],
label="Choose a calming exercise"
)
grounding_btn = gr.Button("Start Exercise ๐ฟ")
grounding_output = gr.Markdown()
grounding_btn.click(
fn=grounding_response,
inputs=grounding_choice,
outputs=grounding_output
)
# Healthy Fuel Tab
with gr.Tab("๐ Healthy Fuel"):
with gr.Column(elem_classes=["glow-card"]):
gr.HTML("""
<p class="card-title">๐ Healthy Fuel Ideas</p>
<p class="card-subtitle">Sweet. Protein. Balanced.</p>
""")
fuel_choice = gr.Radio(
choices=[
"Sweet but Healthy",
"High Protein Meal",
"Quick Snack",
"Balanced Wellness Tip"
],
label="What are you looking for?"
)
fuel_btn = gr.Button("Get Ideas ๐ฝ๏ธ")
fuel_output = gr.Markdown()
fuel_btn.click(
fn=fuel_response,
inputs=fuel_choice,
outputs=fuel_output
)
with gr.Tab("Relaxing Games "):
with gr.Column(elem_classes=["glow-card"]):
# The Zen headers you want to keep
gr.HTML("""
<p class="card-title">Zen Draws</p>
<p class="card-subtitle">Draw. Enjoy. Relax</p>
""")
# Single-page coloring canvas completely updated for Gradio 6+
draw_pad = gr.ImageEditor(
sources=None, # Clean blank drawing canvas
canvas_size=(800, 600), # Full-page canvas space
type="numpy",
label="Coloring Page",
# Fixed: Removed the incompatible 'sizes' and 'colors' lists
brush=gr.Brush(
default_size=10,
default_color="#ff0000"
)
)
# Resources Tab
with gr.Tab("๐จ Resources"):
with gr.Column(elem_classes=["glow-card"]):
gr.HTML("""
<p class="card-title">๐จ Support Resources</p>
<p class="card-subtitle">You deserve support, especially when things feel heavy.</p>
""")
gr.Markdown("""
### Immediate Help
If you are in immediate danger, call emergency services right away.
### United States
- 988 Suicide & Crisis Lifeline
- Call or text 988
### Other Support Options
- Talk to a trusted adult
- Reach out to a school counselor
- Contact a mental health professional
- Message a trusted friend or family member
### Reminder
GlowGuide is an AI assistant, not a therapist, doctor, dietitian, or emergency service.
""")
gr.HTML("""
<p class="footer-text">
๐ You are stronger than you think. Take it one step at a time. โจ
</p>
""")
if __name__ == "__main__":
demo.launch(css=custom_css) |