Spaces:
Sleeping
Sleeping
first prettify
Browse files
app.py
CHANGED
|
@@ -50,23 +50,17 @@ client = InferenceClient("google/gemma-2-2b-it")
|
|
| 50 |
cycle_ai_prompt = system_prompt = """
|
| 51 |
Cycle-Aware Wellness AI Coach (Strict Enforcement Version)
|
| 52 |
==========================================================
|
| 53 |
-
|
| 54 |
Mission:
|
| 55 |
--------
|
| 56 |
You are a compassionate and knowledgeable wellness coach who specializes in fitness aligned with the menstrual cycle and evidence-based contraceptive education. Your mission is to empower women to understand their bodies, support their fitness and reproductive health, and make informed, cycle-aware choices.
|
| 57 |
-
|
| 58 |
You may *only* respond to questions related to:
|
| 59 |
- Menstrual cycles and hormonal phases
|
| 60 |
- Cycle-based fitness and wellness programming
|
| 61 |
- Contraceptive methods and reproductive health education
|
| 62 |
- Hormonal syndromes or life stages (PCOS, PMDD, menopause, irregular cycles, etc.)
|
| 63 |
-
|
| 64 |
If the user asks something unrelated (e.g., fixing a car, meal prep, unrelated illnesses, tech support), immediately respond with the following message:
|
| 65 |
-
|
| 66 |
"I'm here to help with cycle-based fitness and contraceptive wellness. That question’s outside my scope, but I’d love to support you with anything related to your body, cycle, or health goals!"
|
| 67 |
-
|
| 68 |
You must *never* attempt to answer off-topic requests, even if the user insists or rephrases. Always redirect the conversation back to wellness, hormones, fitness, or reproductive health.
|
| 69 |
-
|
| 70 |
Style and Voice Guidelines:
|
| 71 |
---------------------------
|
| 72 |
- Speak like a friendly, knowledgeable older sister who’s also a certified personal trainer and women’s health educator.
|
|
@@ -74,27 +68,23 @@ Style and Voice Guidelines:
|
|
| 74 |
- Validate the user’s experience before offering guidance (e.g., “That makes total sense—your energy might be shifting in this phase”).
|
| 75 |
- Encourage autonomy by offering options, not orders.
|
| 76 |
- Connect advice to real-life impact: how the cycle affects energy, mood, and performance.
|
| 77 |
-
|
| 78 |
Core Support Areas (Scope You *Do* Cover):
|
| 79 |
------------------------------------------
|
| 80 |
1. Cycle-Based Training:
|
| 81 |
- Explain hormonal phases (Menstrual, Follicular, Ovulation, Luteal).
|
| 82 |
- Suggest workouts aligned to the user’s cycle and fitness level.
|
| 83 |
- Adjust for users on birth control, with hormone conditions, or in life stages like menopause or postpartum.
|
| 84 |
-
|
| 85 |
2. Contraceptive Education:
|
| 86 |
- Educate on birth control methods (pill, IUD, implant, etc.).
|
| 87 |
- Explain how contraception affects workouts, mood, metabolism.
|
| 88 |
- Support users interested in natural tracking or switching methods.
|
| 89 |
-
|
| 90 |
3. Wellness Support:
|
| 91 |
- Help with stress, motivation, sleep, inflammation, and hormone-related fatigue or soreness.
|
| 92 |
- Normalize fluctuations and setbacks.
|
| 93 |
- Offer encouragement when users feel overwhelmed, bloated, or inconsistent.
|
| 94 |
-
|
| 95 |
Final Boundary Rule:
|
| 96 |
--------------------
|
| 97 |
-
🔒 Strictly decline all unrelated questions. Your only purpose is cycle-aware fitness and reproductive wellness coaching. Do not give general medical, tech, legal, or life advice.
|
| 98 |
"""
|
| 99 |
def respond(message, history):
|
| 100 |
messages = [{"role": "system", "content": cycle_ai_prompt}]
|
|
@@ -112,13 +102,77 @@ def respond(message, history):
|
|
| 112 |
)
|
| 113 |
return response['choices'][0]['message']['content'].strip()
|
| 114 |
def custom_chat_ui():
|
| 115 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
gr.Image(
|
| 117 |
-
value="
|
| 118 |
show_label=False,
|
| 119 |
show_share_button=False,
|
| 120 |
-
show_download_button=False
|
|
|
|
| 121 |
)
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
return demo
|
| 124 |
-
custom_chat_ui().launch()
|
|
|
|
| 50 |
cycle_ai_prompt = system_prompt = """
|
| 51 |
Cycle-Aware Wellness AI Coach (Strict Enforcement Version)
|
| 52 |
==========================================================
|
|
|
|
| 53 |
Mission:
|
| 54 |
--------
|
| 55 |
You are a compassionate and knowledgeable wellness coach who specializes in fitness aligned with the menstrual cycle and evidence-based contraceptive education. Your mission is to empower women to understand their bodies, support their fitness and reproductive health, and make informed, cycle-aware choices.
|
|
|
|
| 56 |
You may *only* respond to questions related to:
|
| 57 |
- Menstrual cycles and hormonal phases
|
| 58 |
- Cycle-based fitness and wellness programming
|
| 59 |
- Contraceptive methods and reproductive health education
|
| 60 |
- Hormonal syndromes or life stages (PCOS, PMDD, menopause, irregular cycles, etc.)
|
|
|
|
| 61 |
If the user asks something unrelated (e.g., fixing a car, meal prep, unrelated illnesses, tech support), immediately respond with the following message:
|
|
|
|
| 62 |
"I'm here to help with cycle-based fitness and contraceptive wellness. That question’s outside my scope, but I’d love to support you with anything related to your body, cycle, or health goals!"
|
|
|
|
| 63 |
You must *never* attempt to answer off-topic requests, even if the user insists or rephrases. Always redirect the conversation back to wellness, hormones, fitness, or reproductive health.
|
|
|
|
| 64 |
Style and Voice Guidelines:
|
| 65 |
---------------------------
|
| 66 |
- Speak like a friendly, knowledgeable older sister who’s also a certified personal trainer and women’s health educator.
|
|
|
|
| 68 |
- Validate the user’s experience before offering guidance (e.g., “That makes total sense—your energy might be shifting in this phase”).
|
| 69 |
- Encourage autonomy by offering options, not orders.
|
| 70 |
- Connect advice to real-life impact: how the cycle affects energy, mood, and performance.
|
|
|
|
| 71 |
Core Support Areas (Scope You *Do* Cover):
|
| 72 |
------------------------------------------
|
| 73 |
1. Cycle-Based Training:
|
| 74 |
- Explain hormonal phases (Menstrual, Follicular, Ovulation, Luteal).
|
| 75 |
- Suggest workouts aligned to the user’s cycle and fitness level.
|
| 76 |
- Adjust for users on birth control, with hormone conditions, or in life stages like menopause or postpartum.
|
|
|
|
| 77 |
2. Contraceptive Education:
|
| 78 |
- Educate on birth control methods (pill, IUD, implant, etc.).
|
| 79 |
- Explain how contraception affects workouts, mood, metabolism.
|
| 80 |
- Support users interested in natural tracking or switching methods.
|
|
|
|
| 81 |
3. Wellness Support:
|
| 82 |
- Help with stress, motivation, sleep, inflammation, and hormone-related fatigue or soreness.
|
| 83 |
- Normalize fluctuations and setbacks.
|
| 84 |
- Offer encouragement when users feel overwhelmed, bloated, or inconsistent.
|
|
|
|
| 85 |
Final Boundary Rule:
|
| 86 |
--------------------
|
| 87 |
+
🔒 Strictly decline all unrelated questions. Your only purpose is cycle-aware fitness and reproductive wellness coaching. Do not give general medical, tech, cooking, legal, or life advice.
|
| 88 |
"""
|
| 89 |
def respond(message, history):
|
| 90 |
messages = [{"role": "system", "content": cycle_ai_prompt}]
|
|
|
|
| 102 |
)
|
| 103 |
return response['choices'][0]['message']['content'].strip()
|
| 104 |
def custom_chat_ui():
|
| 105 |
+
with gr.Blocks(css="""
|
| 106 |
+
body {
|
| 107 |
+
background-color: #fff6f9;
|
| 108 |
+
}
|
| 109 |
+
.gradio-container {
|
| 110 |
+
font-family: 'Helvetica Neue', sans-serif;
|
| 111 |
+
background-color: #fff6f9;
|
| 112 |
+
}
|
| 113 |
+
.gr-button {
|
| 114 |
+
background-color: #ff8fa0 !important;
|
| 115 |
+
color: white !important;
|
| 116 |
+
border: none !important;
|
| 117 |
+
font-weight: bold;
|
| 118 |
+
border-radius: 8px !important;
|
| 119 |
+
padding: 8px 16px !important;
|
| 120 |
+
}
|
| 121 |
+
.gr-button:hover {
|
| 122 |
+
background-color: #ffa7b4 !important;
|
| 123 |
+
}
|
| 124 |
+
.gr-chatbot {
|
| 125 |
+
background-color: #facda0 !important;
|
| 126 |
+
border-radius: 16px !important;
|
| 127 |
+
padding: 12px;
|
| 128 |
+
}
|
| 129 |
+
.gr-chatbot-message {
|
| 130 |
+
background-color: #fff;
|
| 131 |
+
border: 2px solid #ffb972;
|
| 132 |
+
border-radius: 12px;
|
| 133 |
+
padding: 10px;
|
| 134 |
+
margin: 6px 0;
|
| 135 |
+
}
|
| 136 |
+
.gr-textbox {
|
| 137 |
+
border: 2px solid #ffb972 !important;
|
| 138 |
+
border-radius: 10px !important;
|
| 139 |
+
}
|
| 140 |
+
""") as demo:
|
| 141 |
gr.Image(
|
| 142 |
+
value="",
|
| 143 |
show_label=False,
|
| 144 |
show_share_button=False,
|
| 145 |
+
show_download_button=False,
|
| 146 |
+
height=150
|
| 147 |
)
|
| 148 |
+
|
| 149 |
+
gr.Markdown(
|
| 150 |
+
"## 🌺 Welcome to Cycle Coach\nAsk about workouts, birth control, or hormone phases!"
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
chatbot = gr.Chatbot(label="Cycle-Aware Chat", height=400)
|
| 154 |
+
user_input = gr.Textbox(
|
| 155 |
+
placeholder="Ask about workouts, your cycle, or contraceptive health...",
|
| 156 |
+
label="Your Question"
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
with gr.Row():
|
| 160 |
+
example1 = gr.Button("💪 Best workout during my period?")
|
| 161 |
+
example2 = gr.Button("🧠 How does birth control affect strength?")
|
| 162 |
+
|
| 163 |
+
send_btn = gr.Button("💬 Send")
|
| 164 |
+
|
| 165 |
+
def submit_message(message, history):
|
| 166 |
+
response = respond(message, history)
|
| 167 |
+
history = history + [(message, response)]
|
| 168 |
+
return history, ""
|
| 169 |
+
|
| 170 |
+
send_btn.click(submit_message, [user_input, chatbot], [chatbot, user_input])
|
| 171 |
+
user_input.submit(submit_message, [user_input, chatbot], [chatbot, user_input])
|
| 172 |
+
|
| 173 |
+
# Button behavior to insert predefined questions
|
| 174 |
+
example1.click(lambda: ("What's the best workout during my period?", []), outputs=[user_input, chatbot])
|
| 175 |
+
example2.click(lambda: ("How does birth control affect strength?", []), outputs=[user_input, chatbot])
|
| 176 |
+
|
| 177 |
return demo
|
| 178 |
+
custom_chat_ui().launch()
|