Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -55,23 +55,6 @@ GUIDES = {
|
|
| 55 |
# Themes
|
| 56 |
THEME_KEYS = ["family", "friends", "romance", "silly", "education"]
|
| 57 |
|
| 58 |
-
THEME_LABELS = {
|
| 59 |
-
"fr": {
|
| 60 |
-
"family": "famille",
|
| 61 |
-
"friends": "amis",
|
| 62 |
-
"romance": "romance",
|
| 63 |
-
"silly": "décalé",
|
| 64 |
-
"education": "éducation",
|
| 65 |
-
},
|
| 66 |
-
"en": {
|
| 67 |
-
"family": "family",
|
| 68 |
-
"friends": "friends",
|
| 69 |
-
"romance": "romance",
|
| 70 |
-
"silly": "silly",
|
| 71 |
-
"education": "education",
|
| 72 |
-
},
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
THEME_DESCRIPTIONS = {
|
| 76 |
"fr": {
|
| 77 |
"family": "Thème famille : liens intergénérationnels, rituels familiaux, souvenirs partagés.",
|
|
@@ -667,25 +650,6 @@ def _map_category(choice: str) -> str:
|
|
| 667 |
}
|
| 668 |
return mapping.get(choice, "alimentation")
|
| 669 |
|
| 670 |
-
def _map_theme(label: str, lang: str) -> str:
|
| 671 |
-
"""
|
| 672 |
-
Convert the user-visible theme label back to its internal key.
|
| 673 |
-
Works for both languages and also accepts the key itself as fallback.
|
| 674 |
-
"""
|
| 675 |
-
label = (label or "").strip().lower()
|
| 676 |
-
|
| 677 |
-
# First check if it's already a key
|
| 678 |
-
if label in THEME_KEYS:
|
| 679 |
-
return label
|
| 680 |
-
|
| 681 |
-
# Otherwise map via THEME_LABELS
|
| 682 |
-
for key in THEME_KEYS:
|
| 683 |
-
if label == THEME_LABELS["fr"][key].lower() or label == THEME_LABELS["en"][key].lower():
|
| 684 |
-
return key
|
| 685 |
-
|
| 686 |
-
# Fallback
|
| 687 |
-
return "family"
|
| 688 |
-
|
| 689 |
|
| 690 |
def _card_html(category_key: str, kind: str, title: str, body: str, delay_s: float) -> str:
|
| 691 |
kind_attr = "question" if kind == "q" else "micro"
|
|
@@ -698,10 +662,9 @@ def _card_html(category_key: str, kind: str, title: str, body: str, delay_s: flo
|
|
| 698 |
)
|
| 699 |
|
| 700 |
|
| 701 |
-
def update_cards(lang: str, category_choice: str,
|
| 702 |
category_key = _map_category(category_choice)
|
| 703 |
-
|
| 704 |
-
result = get_questions_and_micro(lang, category_key, theme_key, seen or [])
|
| 705 |
questions = result["questions"]
|
| 706 |
micro = result["micro_actions"]
|
| 707 |
new_seen = result["seen"]
|
|
@@ -753,13 +716,13 @@ def update_cards(lang: str, category_choice: str, theme_choice: str, seen: List[
|
|
| 753 |
def get_ui_texts(lang: str) -> Dict[str, Any]:
|
| 754 |
if lang == "fr":
|
| 755 |
header = """
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
</div>
|
| 762 |
-
|
| 763 |
"""
|
| 764 |
|
| 765 |
category_choices = [
|
|
@@ -769,7 +732,6 @@ def get_ui_texts(lang: str) -> Dict[str, Any]:
|
|
| 769 |
"liens 🤝",
|
| 770 |
"bien-etre 💬",
|
| 771 |
]
|
| 772 |
-
theme_choices = [THEME_LABELS["fr"][k] for k in THEME_KEYS]
|
| 773 |
return {
|
| 774 |
"header_html": header,
|
| 775 |
"language_label": "Langue",
|
|
@@ -780,8 +742,6 @@ def get_ui_texts(lang: str) -> Dict[str, Any]:
|
|
| 780 |
"button_text": "Générer un tirage ✨",
|
| 781 |
"category_choices": category_choices,
|
| 782 |
"category_default": "alimentation 🍎",
|
| 783 |
-
"theme_choices": theme_choices,
|
| 784 |
-
"theme_default": THEME_LABELS["fr"]["family"],
|
| 785 |
}
|
| 786 |
else:
|
| 787 |
header = """
|
|
@@ -801,7 +761,6 @@ def get_ui_texts(lang: str) -> Dict[str, Any]:
|
|
| 801 |
"Connections 🤝",
|
| 802 |
"Well-being 💬",
|
| 803 |
]
|
| 804 |
-
theme_choices = [THEME_LABELS["en"][k] for k in THEME_KEYS]
|
| 805 |
return {
|
| 806 |
"header_html": header,
|
| 807 |
"language_label": "Language",
|
|
@@ -812,8 +771,6 @@ def get_ui_texts(lang: str) -> Dict[str, Any]:
|
|
| 812 |
"button_text": "Generate card set ✨",
|
| 813 |
"category_choices": category_choices,
|
| 814 |
"category_default": "Nutrition 🍎",
|
| 815 |
-
"theme_choices": theme_choices,
|
| 816 |
-
"theme_default": THEME_LABELS["en"]["family"],
|
| 817 |
}
|
| 818 |
|
| 819 |
|
|
@@ -826,15 +783,13 @@ def update_ui_language(lang: str):
|
|
| 826 |
f"<div class='nv-label nv-fade'>{t['category_label']}</div>",
|
| 827 |
f"<div class='nv-label nv-fade'>{t['questions_label']}</div>",
|
| 828 |
f"<div class='nv-label nv-fade'>{t['micro_label']}</div>",
|
| 829 |
-
gr.update(choices=t["theme_choices"], value=t["theme_default"]),
|
| 830 |
gr.update(choices=t["category_choices"], value=t["category_default"]),
|
| 831 |
-
gr.update(value=t[
|
| 832 |
)
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
-
|
| 838 |
# ────────────────────────────────────────────────────────────────────────────────
|
| 839 |
# GRADIO APP
|
| 840 |
|
|
@@ -872,15 +827,14 @@ with gr.Blocks(title="Neurovie – Question Studio") as demo:
|
|
| 872 |
f"<div class='nv-label nv-fade'>{ui_texts['theme_label']}</div>"
|
| 873 |
)
|
| 874 |
theme = gr.Radio(
|
| 875 |
-
choices=
|
| 876 |
-
value=
|
| 877 |
show_label=False,
|
| 878 |
elem_classes="nv-pills",
|
| 879 |
)
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
-
|
| 884 |
with gr.Column(elem_classes="nv-section"):
|
| 885 |
category_label_html = gr.HTML(f"<div class='nv-label nv-fade'>{ui_texts['category_label']}</div>")
|
| 886 |
category = gr.Radio(
|
|
@@ -918,7 +872,6 @@ with gr.Blocks(title="Neurovie – Question Studio") as demo:
|
|
| 918 |
category_label_html,
|
| 919 |
questions_label_html,
|
| 920 |
micro_label_html,
|
| 921 |
-
theme,
|
| 922 |
category,
|
| 923 |
btn,
|
| 924 |
],
|
|
|
|
| 55 |
# Themes
|
| 56 |
THEME_KEYS = ["family", "friends", "romance", "silly", "education"]
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
THEME_DESCRIPTIONS = {
|
| 59 |
"fr": {
|
| 60 |
"family": "Thème famille : liens intergénérationnels, rituels familiaux, souvenirs partagés.",
|
|
|
|
| 650 |
}
|
| 651 |
return mapping.get(choice, "alimentation")
|
| 652 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
|
| 654 |
def _card_html(category_key: str, kind: str, title: str, body: str, delay_s: float) -> str:
|
| 655 |
kind_attr = "question" if kind == "q" else "micro"
|
|
|
|
| 662 |
)
|
| 663 |
|
| 664 |
|
| 665 |
+
def update_cards(lang: str, category_choice: str, theme: str, seen: List[str]):
|
| 666 |
category_key = _map_category(category_choice)
|
| 667 |
+
result = get_questions_and_micro(lang, category_key, theme, seen or [])
|
|
|
|
| 668 |
questions = result["questions"]
|
| 669 |
micro = result["micro_actions"]
|
| 670 |
new_seen = result["seen"]
|
|
|
|
| 716 |
def get_ui_texts(lang: str) -> Dict[str, Any]:
|
| 717 |
if lang == "fr":
|
| 718 |
header = """
|
| 719 |
+
<div class="nv-fade">
|
| 720 |
+
<div class="nv-badge">NEUROVIE · FINGER</div>
|
| 721 |
+
<div class="nv-title">Question Studio</div>
|
| 722 |
+
<div class="nv-subtitle">
|
| 723 |
+
Questions minimalistes pour conversations riches — 4 questions et 2 micro-actions par tirage.
|
| 724 |
</div>
|
| 725 |
+
</div>
|
| 726 |
"""
|
| 727 |
|
| 728 |
category_choices = [
|
|
|
|
| 732 |
"liens 🤝",
|
| 733 |
"bien-etre 💬",
|
| 734 |
]
|
|
|
|
| 735 |
return {
|
| 736 |
"header_html": header,
|
| 737 |
"language_label": "Langue",
|
|
|
|
| 742 |
"button_text": "Générer un tirage ✨",
|
| 743 |
"category_choices": category_choices,
|
| 744 |
"category_default": "alimentation 🍎",
|
|
|
|
|
|
|
| 745 |
}
|
| 746 |
else:
|
| 747 |
header = """
|
|
|
|
| 761 |
"Connections 🤝",
|
| 762 |
"Well-being 💬",
|
| 763 |
]
|
|
|
|
| 764 |
return {
|
| 765 |
"header_html": header,
|
| 766 |
"language_label": "Language",
|
|
|
|
| 771 |
"button_text": "Generate card set ✨",
|
| 772 |
"category_choices": category_choices,
|
| 773 |
"category_default": "Nutrition 🍎",
|
|
|
|
|
|
|
| 774 |
}
|
| 775 |
|
| 776 |
|
|
|
|
| 783 |
f"<div class='nv-label nv-fade'>{t['category_label']}</div>",
|
| 784 |
f"<div class='nv-label nv-fade'>{t['questions_label']}</div>",
|
| 785 |
f"<div class='nv-label nv-fade'>{t['micro_label']}</div>",
|
|
|
|
| 786 |
gr.update(choices=t["category_choices"], value=t["category_default"]),
|
| 787 |
+
gr.update(value=t['button_text']),
|
| 788 |
)
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
|
|
|
| 793 |
# ────────────────────────────────────────────────────────────────────────────────
|
| 794 |
# GRADIO APP
|
| 795 |
|
|
|
|
| 827 |
f"<div class='nv-label nv-fade'>{ui_texts['theme_label']}</div>"
|
| 828 |
)
|
| 829 |
theme = gr.Radio(
|
| 830 |
+
choices=THEME_KEYS,
|
| 831 |
+
value="family",
|
| 832 |
show_label=False,
|
| 833 |
elem_classes="nv-pills",
|
| 834 |
)
|
| 835 |
|
| 836 |
|
| 837 |
|
|
|
|
| 838 |
with gr.Column(elem_classes="nv-section"):
|
| 839 |
category_label_html = gr.HTML(f"<div class='nv-label nv-fade'>{ui_texts['category_label']}</div>")
|
| 840 |
category = gr.Radio(
|
|
|
|
| 872 |
category_label_html,
|
| 873 |
questions_label_html,
|
| 874 |
micro_label_html,
|
|
|
|
| 875 |
category,
|
| 876 |
btn,
|
| 877 |
],
|
style.css
CHANGED
|
@@ -258,22 +258,23 @@
|
|
| 258 |
font-size: 0.9rem;
|
| 259 |
border: 1px solid rgba(0, 0, 0, 0.03);
|
| 260 |
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
|
| 261 |
-
opacity: 1;
|
| 262 |
transform: translateY(0) scale(1);
|
| 263 |
animation: nvCardDeal 420ms ease-out forwards;
|
| 264 |
cursor: default;
|
| 265 |
transition:
|
| 266 |
box-shadow 180ms ease,
|
| 267 |
-
transform 180ms ease
|
|
|
|
| 268 |
}
|
| 269 |
|
| 270 |
-
|
| 271 |
.nv-card:hover {
|
| 272 |
box-shadow: 0 12px 24px rgba(15, 23, 42, 0.15);
|
| 273 |
transform: translateY(-4px) scale(1.03);
|
| 274 |
}
|
| 275 |
|
| 276 |
|
|
|
|
| 277 |
/* Category color themes */
|
| 278 |
|
| 279 |
.nv-card--cat-alimentation {
|
|
|
|
| 258 |
font-size: 0.9rem;
|
| 259 |
border: 1px solid rgba(0, 0, 0, 0.03);
|
| 260 |
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
|
| 261 |
+
opacity: 1;
|
| 262 |
transform: translateY(0) scale(1);
|
| 263 |
animation: nvCardDeal 420ms ease-out forwards;
|
| 264 |
cursor: default;
|
| 265 |
transition:
|
| 266 |
box-shadow 180ms ease,
|
| 267 |
+
transform 180ms ease,
|
| 268 |
+
opacity 240ms ease;
|
| 269 |
}
|
| 270 |
|
|
|
|
| 271 |
.nv-card:hover {
|
| 272 |
box-shadow: 0 12px 24px rgba(15, 23, 42, 0.15);
|
| 273 |
transform: translateY(-4px) scale(1.03);
|
| 274 |
}
|
| 275 |
|
| 276 |
|
| 277 |
+
|
| 278 |
/* Category color themes */
|
| 279 |
|
| 280 |
.nv-card--cat-alimentation {
|