Spaces:
Sleeping
Sleeping
Added the ability to configure custom prompts for the main lifestyle assistant. Implemented methods for setting, resetting to default, and getting the current prompt. Updated the Gradio interface for editing prompts, including a new “Edit Prompts” tab with the ability to preview changes. Added instructions for using prompt customization in the documentation. Made changes to the lifestyle profile to synchronize custom prompts with the session.
Browse files- INSTRUCTION.md +152 -6
- core_classes.py +19 -0
- gradio_interface.py +213 -8
- lifestyle_app.py +25 -1
- lifestyle_profile.json +8 -36
- lifestyle_profile.json.backup +64 -0
INSTRUCTION.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
- 🩺 **Get medical consultations** for symptoms and health concerns
|
| 7 |
- 💚 **Develop personalized programs** for physical activity and nutrition
|
| 8 |
- 📊 **Track progress** of your healthy lifestyle journey
|
|
|
|
| 9 |
- 🔒 **Maintain privacy** - your data remains confidential and isolated
|
| 10 |
|
| 11 |
---
|
|
@@ -54,6 +55,7 @@ Simply type your question in the text field and click "📤 Send"
|
|
| 54 |
- Provides nutrition advice
|
| 55 |
- Considers your medical limitations
|
| 56 |
- Motivates and supports you
|
|
|
|
| 57 |
|
| 58 |
**Example questions:**
|
| 59 |
- "I want to lose 10 kg"
|
|
@@ -70,10 +72,63 @@ The app will first address the medical issue, then help with physical activity.
|
|
| 70 |
|
| 71 |
---
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
## 🧪 Testing with Different Patients
|
| 74 |
|
| 75 |
### **What is this?**
|
| 76 |
-
In the "🧪 Testing Lab" tab, you can load profiles of different patients to test functionality.
|
| 77 |
|
| 78 |
### **Ready-made test patients:**
|
| 79 |
- **👵 Elderly Mary** - 76 years old, complex chronic conditions
|
|
@@ -85,6 +140,7 @@ In the "🧪 Testing Lab" tab, you can load profiles of different patients to te
|
|
| 85 |
2. Click on one of the buttons (e.g., "👵 Elderly Mary")
|
| 86 |
3. Chat will restart with the new patient
|
| 87 |
4. Now you can test different scenarios for this patient
|
|
|
|
| 88 |
|
| 89 |
### **Loading custom data:**
|
| 90 |
1. Prepare JSON files with medical data and lifestyle profile
|
|
@@ -99,21 +155,32 @@ In the "🧪 Testing Lab" tab, you can load profiles of different patients to te
|
|
| 99 |
- **Be specific:** "Morning headache" is better than "feeling bad"
|
| 100 |
- **Provide context:** "I have diabetes and want to exercise"
|
| 101 |
- **Ask direct questions:** "How many times per week should I train?"
|
|
|
|
| 102 |
|
| 103 |
### **🔒 Safety and Privacy:**
|
| 104 |
- Your data is not stored on servers
|
| 105 |
- Each session is isolated from other users
|
|
|
|
| 106 |
- All data is deleted when you close the browser
|
| 107 |
|
| 108 |
### **⚠️ Medical Safety:**
|
| 109 |
- The app does NOT replace doctor consultation
|
| 110 |
- For serious symptoms, always contact medical professionals
|
| 111 |
- Don't make important medical decisions without a doctor
|
|
|
|
| 112 |
|
| 113 |
### **🎯 Lifestyle Tips:**
|
| 114 |
- Start with small steps
|
| 115 |
- Follow recommendations regarding your limitations
|
| 116 |
- Regularly update your progress
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
---
|
| 119 |
|
|
@@ -125,9 +192,16 @@ In the "🧪 Testing Lab" tab, you can load profiles of different patients to te
|
|
| 125 |
- **🏁 End Conversation** - End conversation and save progress
|
| 126 |
- **🔄 Refresh Status** - Update system status information
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
### **Ending your session:**
|
| 129 |
1. Click "🏁 End Conversation" to save progress
|
| 130 |
2. Or simply close the browser - session will end automatically
|
|
|
|
| 131 |
|
| 132 |
---
|
| 133 |
|
|
@@ -140,7 +214,7 @@ The app automatically determines your question type and chooses the best respons
|
|
| 140 |
You can tell the app about your conditions during conversation, and it will consider them in recommendations.
|
| 141 |
|
| 142 |
### **❓ What to do if the response is inaccurate?**
|
| 143 |
-
Clarify your question or provide more details.
|
| 144 |
|
| 145 |
### **❓ Is it safe to share medical information?**
|
| 146 |
Yes, your data is processed locally and not shared with third parties.
|
|
@@ -148,21 +222,93 @@ Yes, your data is processed locally and not shared with third parties.
|
|
| 148 |
### **❓ How to get help in an urgent situation?**
|
| 149 |
For serious symptoms, the app will advise you to immediately contact emergency services or a doctor.
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
---
|
| 152 |
|
| 153 |
## 📞 Support
|
| 154 |
|
| 155 |
If you have questions or problems:
|
| 156 |
1. Try restarting the session with the "🗑️ Clear Chat" button
|
| 157 |
-
2.
|
| 158 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
---
|
| 161 |
|
| 162 |
## 🌟 Successful Usage!
|
| 163 |
|
| 164 |
-
**Lifestyle Journey** is created to make health care simpler and more accessible.
|
| 165 |
|
| 166 |
**Remember:** This app is your assistant, but not a replacement for professional medical help. Always consult with a doctor for serious health problems.
|
| 167 |
|
| 168 |
-
🎯 **We wish you strong health and an active lifestyle!**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- 🩺 **Get medical consultations** for symptoms and health concerns
|
| 7 |
- 💚 **Develop personalized programs** for physical activity and nutrition
|
| 8 |
- 📊 **Track progress** of your healthy lifestyle journey
|
| 9 |
+
- 🔧 **Customize AI behavior** with personalized prompts for coaching style
|
| 10 |
- 🔒 **Maintain privacy** - your data remains confidential and isolated
|
| 11 |
|
| 12 |
---
|
|
|
|
| 55 |
- Provides nutrition advice
|
| 56 |
- Considers your medical limitations
|
| 57 |
- Motivates and supports you
|
| 58 |
+
- **Can be customized** with your preferred coaching style
|
| 59 |
|
| 60 |
**Example questions:**
|
| 61 |
- "I want to lose 10 kg"
|
|
|
|
| 72 |
|
| 73 |
---
|
| 74 |
|
| 75 |
+
## 🔧 Customize Your AI Coach
|
| 76 |
+
|
| 77 |
+
### **What is Edit Prompts?**
|
| 78 |
+
**Edit Prompts** allows you to customize how the AI lifestyle coach behaves and responds to your questions. You can make it more motivating, conservative, or specialized for your needs.
|
| 79 |
+
|
| 80 |
+
### **How to access:**
|
| 81 |
+
1. Click the **"🔧 Edit Prompts"** tab at the top
|
| 82 |
+
2. You'll see the current system prompt that controls AI behavior
|
| 83 |
+
3. Edit the text to match your preferences
|
| 84 |
+
4. Apply changes and test them in chat
|
| 85 |
+
|
| 86 |
+
### **Customization examples:**
|
| 87 |
+
- **Motivational Coach:** "Be energetic, use emojis, say 'You can do it!'"
|
| 88 |
+
- **Medical Conservative:** "Prioritize safety, give very gradual recommendations"
|
| 89 |
+
- **Senior-Friendly:** "Focus on fall prevention and low-intensity activities"
|
| 90 |
+
|
| 91 |
+
### **Important notes:**
|
| 92 |
+
- ⚠️ Changes apply **only to your current session**
|
| 93 |
+
- ⚠️ Changes are **lost when you close the browser**
|
| 94 |
+
- ⚠️ Always maintain **medical safety guidelines**
|
| 95 |
+
- ✅ Easy to **reset to default** if needed
|
| 96 |
+
|
| 97 |
+
### **How to use Edit Prompts:**
|
| 98 |
+
|
| 99 |
+
#### **Step 1: Open Edit Prompts**
|
| 100 |
+
- Click the **"🔧 Edit Prompts"** tab
|
| 101 |
+
- View the current system prompt in the large text box
|
| 102 |
+
|
| 103 |
+
#### **Step 2: Customize**
|
| 104 |
+
- Modify the prompt text according to your needs
|
| 105 |
+
- Use the guidelines in the right panel as reference
|
| 106 |
+
- Focus on tone, style, and approach preferences
|
| 107 |
+
|
| 108 |
+
#### **Step 3: Apply and Test**
|
| 109 |
+
- Click **"✅ Apply Changes"** to activate
|
| 110 |
+
- Click **"🧪 Test"** for testing instructions
|
| 111 |
+
- Go to **"💬 Patient Chat"** tab to try it out
|
| 112 |
+
- Test with: "I want to start exercising"
|
| 113 |
+
|
| 114 |
+
#### **Step 4: Control Buttons**
|
| 115 |
+
- **✅ Apply Changes** - Activate your custom prompt
|
| 116 |
+
- **🔄 Reset to Default** - Return to original behavior
|
| 117 |
+
- **👁️ Preview** - Check your changes before applying
|
| 118 |
+
- **🧪 Test** - Get instructions for testing
|
| 119 |
+
|
| 120 |
+
### **Requirements for custom prompts:**
|
| 121 |
+
- Must return **valid JSON format** with message/action/reasoning
|
| 122 |
+
- Must include **medical safety** guidelines
|
| 123 |
+
- Must handle three actions: `gather_info`, `lifestyle_dialog`, `close`
|
| 124 |
+
- Should respond in the **same language** as the patient
|
| 125 |
+
|
| 126 |
+
---
|
| 127 |
+
|
| 128 |
## 🧪 Testing with Different Patients
|
| 129 |
|
| 130 |
### **What is this?**
|
| 131 |
+
In the "🧪 Testing Lab" tab, you can load profiles of different patients to test functionality and your custom prompts.
|
| 132 |
|
| 133 |
### **Ready-made test patients:**
|
| 134 |
- **👵 Elderly Mary** - 76 years old, complex chronic conditions
|
|
|
|
| 140 |
2. Click on one of the buttons (e.g., "👵 Elderly Mary")
|
| 141 |
3. Chat will restart with the new patient
|
| 142 |
4. Now you can test different scenarios for this patient
|
| 143 |
+
5. **Perfect for testing custom prompts** with different patient types
|
| 144 |
|
| 145 |
### **Loading custom data:**
|
| 146 |
1. Prepare JSON files with medical data and lifestyle profile
|
|
|
|
| 155 |
- **Be specific:** "Morning headache" is better than "feeling bad"
|
| 156 |
- **Provide context:** "I have diabetes and want to exercise"
|
| 157 |
- **Ask direct questions:** "How many times per week should I train?"
|
| 158 |
+
- **Customize AI style:** Use Edit Prompts to match your preferences
|
| 159 |
|
| 160 |
### **🔒 Safety and Privacy:**
|
| 161 |
- Your data is not stored on servers
|
| 162 |
- Each session is isolated from other users
|
| 163 |
+
- **Custom prompts are private** to your session only
|
| 164 |
- All data is deleted when you close the browser
|
| 165 |
|
| 166 |
### **⚠️ Medical Safety:**
|
| 167 |
- The app does NOT replace doctor consultation
|
| 168 |
- For serious symptoms, always contact medical professionals
|
| 169 |
- Don't make important medical decisions without a doctor
|
| 170 |
+
- **Custom prompts cannot override medical safety** protocols
|
| 171 |
|
| 172 |
### **🎯 Lifestyle Tips:**
|
| 173 |
- Start with small steps
|
| 174 |
- Follow recommendations regarding your limitations
|
| 175 |
- Regularly update your progress
|
| 176 |
+
- **Experiment with different coaching styles** to find what motivates you
|
| 177 |
+
|
| 178 |
+
### **🔧 Edit Prompts Best Practices:**
|
| 179 |
+
- **Start small:** Make minor changes to the default prompt first
|
| 180 |
+
- **Test thoroughly:** Always test changes with different questions
|
| 181 |
+
- **Keep safety:** Never remove medical safety instructions
|
| 182 |
+
- **Use Reset:** If something goes wrong, use "🔄 Reset to Default"
|
| 183 |
+
- **Be specific:** Clear instructions give better results
|
| 184 |
|
| 185 |
---
|
| 186 |
|
|
|
|
| 192 |
- **🏁 End Conversation** - End conversation and save progress
|
| 193 |
- **🔄 Refresh Status** - Update system status information
|
| 194 |
|
| 195 |
+
### **Edit Prompts buttons:**
|
| 196 |
+
- **✅ Apply Changes** - Activate your custom prompt
|
| 197 |
+
- **🔄 Reset to Default** - Return to original AI behavior
|
| 198 |
+
- **👁️ Preview** - Review changes before applying
|
| 199 |
+
- **🧪 Test** - Get testing instructions
|
| 200 |
+
|
| 201 |
### **Ending your session:**
|
| 202 |
1. Click "🏁 End Conversation" to save progress
|
| 203 |
2. Or simply close the browser - session will end automatically
|
| 204 |
+
3. **Note:** Custom prompts are lost when closing browser
|
| 205 |
|
| 206 |
---
|
| 207 |
|
|
|
|
| 214 |
You can tell the app about your conditions during conversation, and it will consider them in recommendations.
|
| 215 |
|
| 216 |
### **❓ What to do if the response is inaccurate?**
|
| 217 |
+
Clarify your question or provide more details. Try customizing the AI coaching style with Edit Prompts.
|
| 218 |
|
| 219 |
### **❓ Is it safe to share medical information?**
|
| 220 |
Yes, your data is processed locally and not shared with third parties.
|
|
|
|
| 222 |
### **❓ How to get help in an urgent situation?**
|
| 223 |
For serious symptoms, the app will advise you to immediately contact emergency services or a doctor.
|
| 224 |
|
| 225 |
+
### **❓ What if my custom prompt breaks the AI?**
|
| 226 |
+
Use the "🔄 Reset to Default" button to immediately return to safe, working settings.
|
| 227 |
+
|
| 228 |
+
### **❓ Can other users see my custom prompts?**
|
| 229 |
+
No, your custom prompts are completely private to your session only.
|
| 230 |
+
|
| 231 |
+
### **❓ Why do my prompt changes disappear?**
|
| 232 |
+
Custom prompts are session-only for security. They reset when you close the browser.
|
| 233 |
+
|
| 234 |
+
### **❓ How do I make the AI more motivating?**
|
| 235 |
+
Use Edit Prompts to add instructions like "Be energetic, use positive emojis, motivate with phrases like 'You can do it!'"
|
| 236 |
+
|
| 237 |
---
|
| 238 |
|
| 239 |
## 📞 Support
|
| 240 |
|
| 241 |
If you have questions or problems:
|
| 242 |
1. Try restarting the session with the "🗑️ Clear Chat" button
|
| 243 |
+
2. **If Edit Prompts cause issues:** Use "🔄 Reset to Default"
|
| 244 |
+
3. Check that you're using a supported browser
|
| 245 |
+
4. Rephrase your question more specifically
|
| 246 |
+
|
| 247 |
+
---
|
| 248 |
+
|
| 249 |
+
## 🌟 Advanced Features
|
| 250 |
+
|
| 251 |
+
### **🔧 Edit Prompts Examples**
|
| 252 |
+
|
| 253 |
+
#### **Motivational Coach:**
|
| 254 |
+
```
|
| 255 |
+
You are a super-energetic lifestyle coach who:
|
| 256 |
+
- Always uses positive emojis 🌟💪🚀
|
| 257 |
+
- Says "You can do it!" and "Fantastic!"
|
| 258 |
+
- Celebrates even small achievements
|
| 259 |
+
- Keeps patients motivated and excited
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
#### **Medical Conservative:**
|
| 263 |
+
```
|
| 264 |
+
You are a careful medical coach who:
|
| 265 |
+
- Prioritizes safety above all
|
| 266 |
+
- Explains medical principles clearly
|
| 267 |
+
- Gives very gradual recommendations
|
| 268 |
+
- Always mentions when to consult doctors
|
| 269 |
+
```
|
| 270 |
+
|
| 271 |
+
#### **Senior-Specialized:**
|
| 272 |
+
```
|
| 273 |
+
You are a coach for elderly patients who:
|
| 274 |
+
- Focuses on fall prevention
|
| 275 |
+
- Suggests low-impact activities
|
| 276 |
+
- Considers age-related limitations
|
| 277 |
+
- Emphasizes safety and gradual progress
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
### **🧪 Testing Your Custom Prompts**
|
| 281 |
+
|
| 282 |
+
**Recommended test questions:**
|
| 283 |
+
- "I want to start exercising"
|
| 284 |
+
- "Give me nutrition advice"
|
| 285 |
+
- "I have [condition] but want to be active"
|
| 286 |
+
- "Help me lose weight safely"
|
| 287 |
+
|
| 288 |
+
**What to check:**
|
| 289 |
+
- Does the tone match your expectations?
|
| 290 |
+
- Are responses safe and appropriate?
|
| 291 |
+
- Does it handle medical limitations correctly?
|
| 292 |
+
- Is the JSON format working properly?
|
| 293 |
|
| 294 |
---
|
| 295 |
|
| 296 |
## 🌟 Successful Usage!
|
| 297 |
|
| 298 |
+
**Lifestyle Journey** is created to make health care simpler and more accessible. With the new **Edit Prompts** feature, you can now personalize your AI coach to match your preferred communication style and motivational needs.
|
| 299 |
|
| 300 |
**Remember:** This app is your assistant, but not a replacement for professional medical help. Always consult with a doctor for serious health problems.
|
| 301 |
|
| 302 |
+
🎯 **We wish you strong health and an active lifestyle!**
|
| 303 |
+
|
| 304 |
+
---
|
| 305 |
+
|
| 306 |
+
## 🔗 Quick Navigation
|
| 307 |
+
|
| 308 |
+
- **💬 Patient Chat** - Main conversation interface
|
| 309 |
+
- **🔧 Edit Prompts** - Customize AI coaching style
|
| 310 |
+
- **🧪 Testing Lab** - Test with different patient profiles
|
| 311 |
+
- **📊 Test Results** - View testing analytics
|
| 312 |
+
- **📖 Instructions** - This guide
|
| 313 |
+
|
| 314 |
+
**Happy coaching!** 🏥💚
|
core_classes.py
CHANGED
|
@@ -678,5 +678,24 @@ class MainLifestyleAssistant:
|
|
| 678 |
"action": "gather_info",
|
| 679 |
"reasoning": "Помилка парсингу - переходимо до збору інформації"
|
| 680 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
|
| 682 |
# ===== DEPRECATED: Старий lifestyle асистент (замінено на MainLifestyleAssistant) =====
|
|
|
|
| 678 |
"action": "gather_info",
|
| 679 |
"reasoning": "Помилка парсингу - переходимо до збору інформації"
|
| 680 |
}
|
| 681 |
+
|
| 682 |
+
def __init__(self, api: GeminiAPI):
|
| 683 |
+
self.api = api
|
| 684 |
+
self.custom_system_prompt = None # NEW
|
| 685 |
+
self.default_system_prompt = SYSTEM_PROMPT_MAIN_LIFESTYLE # NEW
|
| 686 |
+
|
| 687 |
+
def set_custom_system_prompt(self, custom_prompt: str):
|
| 688 |
+
"""Set custom system prompt for this session"""
|
| 689 |
+
self.custom_system_prompt = custom_prompt.strip() if custom_prompt and custom_prompt.strip() else None
|
| 690 |
+
|
| 691 |
+
def reset_to_default_prompt(self):
|
| 692 |
+
"""Reset to default system prompt"""
|
| 693 |
+
self.custom_system_prompt = None
|
| 694 |
+
|
| 695 |
+
def get_current_system_prompt(self) -> str:
|
| 696 |
+
"""Get current system prompt (custom or default)"""
|
| 697 |
+
if self.custom_system_prompt:
|
| 698 |
+
return self.custom_system_prompt
|
| 699 |
+
return self.default_system_prompt
|
| 700 |
|
| 701 |
# ===== DEPRECATED: Старий lifestyle асистент (замінено на MainLifestyleAssistant) =====
|
gradio_interface.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# session_isolated_interface.py - Session-isolated Gradio interface with
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
|
@@ -10,6 +10,7 @@ from typing import Dict, Any, Optional
|
|
| 10 |
|
| 11 |
from lifestyle_app import ExtendedLifestyleJourneyApp
|
| 12 |
from core_classes import SessionState, ChatMessage
|
|
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
from app_config import GRADIO_CONFIG
|
|
@@ -23,6 +24,11 @@ class SessionData:
|
|
| 23 |
self.app_instance = ExtendedLifestyleJourneyApp()
|
| 24 |
self.created_at = datetime.now().isoformat()
|
| 25 |
self.last_activity = datetime.now().isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def to_dict(self) -> Dict[str, Any]:
|
| 28 |
"""Serialize session for storage"""
|
|
@@ -33,12 +39,31 @@ class SessionData:
|
|
| 33 |
"chat_history": [asdict(msg) for msg in self.app_instance.chat_history],
|
| 34 |
"session_state": asdict(self.app_instance.session_state),
|
| 35 |
"test_mode_active": self.app_instance.test_mode_active,
|
| 36 |
-
"current_test_patient": self.app_instance.current_test_patient
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
def update_activity(self):
|
| 40 |
"""Update last activity timestamp"""
|
| 41 |
self.last_activity = datetime.now().isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def load_instructions() -> str:
|
| 44 |
"""Load instructions from INSTRUCTION.md file"""
|
|
@@ -77,7 +102,7 @@ For help, type "help" or "how to use" in the chat.
|
|
| 77 |
"""
|
| 78 |
|
| 79 |
def create_session_isolated_interface():
|
| 80 |
-
"""Create session-isolated Gradio interface with
|
| 81 |
|
| 82 |
log_prompts_enabled = os.getenv("LOG_PROMPTS", "false").lower() == "true"
|
| 83 |
|
|
@@ -99,12 +124,12 @@ def create_session_isolated_interface():
|
|
| 99 |
|
| 100 |
# Header
|
| 101 |
if log_prompts_enabled:
|
| 102 |
-
gr.Markdown("# 🏥 Lifestyle Journey MVP + 🧪 Testing Lab 📝")
|
| 103 |
gr.Markdown("⚠️ **DEBUG MODE:** LLM prompts and responses are saved to `lifestyle_journey.log`")
|
| 104 |
else:
|
| 105 |
-
gr.Markdown("# 🏥 Lifestyle Journey MVP + 🧪 Testing Lab")
|
| 106 |
|
| 107 |
-
gr.Markdown("Medical chatbot with lifestyle coaching
|
| 108 |
|
| 109 |
# Session info
|
| 110 |
with gr.Row():
|
|
@@ -119,6 +144,7 @@ def create_session_isolated_interface():
|
|
| 119 |
🆔 **Session ID:** `{new_session.session_id[:8]}...`
|
| 120 |
🕒 **Started:** {new_session.created_at[:19]}
|
| 121 |
👤 **Isolated Instance:** Each user has separate data
|
|
|
|
| 122 |
"""
|
| 123 |
return new_session, session_info_text
|
| 124 |
|
|
@@ -163,6 +189,60 @@ def create_session_isolated_interface():
|
|
| 163 |
refresh_status_btn = gr.Button("🔄 Refresh Status", size="sm")
|
| 164 |
|
| 165 |
end_conversation_result = gr.Markdown(value="", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# Testing Lab tab
|
| 168 |
with gr.TabItem("🧪 Testing Lab", id="testing_lab"):
|
|
@@ -229,7 +309,7 @@ def create_session_isolated_interface():
|
|
| 229 |
value=[]
|
| 230 |
)
|
| 231 |
|
| 232 |
-
# Instructions tab
|
| 233 |
with gr.TabItem("📖 Instructions", id="instructions"):
|
| 234 |
gr.Markdown("## 📚 User Guide")
|
| 235 |
|
|
@@ -250,6 +330,7 @@ def create_session_isolated_interface():
|
|
| 250 |
medical_example_btn = gr.Button("🩺 Medical Example", size="sm")
|
| 251 |
lifestyle_example_btn = gr.Button("💚 Lifestyle Example", size="sm")
|
| 252 |
testing_example_btn = gr.Button("🧪 Testing", size="sm")
|
|
|
|
| 253 |
|
| 254 |
gr.Markdown("### 📞 Help")
|
| 255 |
refresh_instructions_btn = gr.Button("🔄 Refresh Instructions", size="sm")
|
|
@@ -313,17 +394,117 @@ def create_session_isolated_interface():
|
|
| 313 |
|
| 314 |
session.update_activity()
|
| 315 |
base_status = session.app_instance._get_status_info()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
session_status = f"""
|
| 317 |
🔐 **SESSION ISOLATION:**
|
| 318 |
• Session ID: {session.session_id[:8]}...
|
| 319 |
• Created: {session.created_at[:19]}
|
| 320 |
• Last Activity: {session.last_activity[:19]}
|
| 321 |
• Isolated: ✅ Your data is private
|
| 322 |
-
|
| 323 |
{base_status}
|
| 324 |
"""
|
| 325 |
return session_status
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
# Helper functions for examples and instructions
|
| 328 |
def send_example_message(example_text: str, history, session: SessionData):
|
| 329 |
"""Send example message to chat"""
|
|
@@ -404,6 +585,25 @@ def create_session_isolated_interface():
|
|
| 404 |
outputs=[status_box]
|
| 405 |
)
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
# Quick example buttons in chat
|
| 408 |
example_medical_btn.click(
|
| 409 |
lambda history, session: send_example_message("I have a headache", history, session),
|
|
@@ -445,6 +645,11 @@ def create_session_isolated_interface():
|
|
| 445 |
outputs=[]
|
| 446 |
)
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
# Testing Lab handlers with session isolation
|
| 449 |
load_patient_btn.click(
|
| 450 |
handle_load_patient_isolated,
|
|
|
|
| 1 |
+
# session_isolated_interface.py - Session-isolated Gradio interface with Edit Prompts tab
|
| 2 |
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
|
|
|
| 10 |
|
| 11 |
from lifestyle_app import ExtendedLifestyleJourneyApp
|
| 12 |
from core_classes import SessionState, ChatMessage
|
| 13 |
+
from prompts import SYSTEM_PROMPT_MAIN_LIFESTYLE
|
| 14 |
|
| 15 |
try:
|
| 16 |
from app_config import GRADIO_CONFIG
|
|
|
|
| 24 |
self.app_instance = ExtendedLifestyleJourneyApp()
|
| 25 |
self.created_at = datetime.now().isoformat()
|
| 26 |
self.last_activity = datetime.now().isoformat()
|
| 27 |
+
# NEW: Custom prompts storage
|
| 28 |
+
self.custom_prompts = {
|
| 29 |
+
"main_lifestyle": SYSTEM_PROMPT_MAIN_LIFESTYLE # Default prompt
|
| 30 |
+
}
|
| 31 |
+
self.prompts_modified = False
|
| 32 |
|
| 33 |
def to_dict(self) -> Dict[str, Any]:
|
| 34 |
"""Serialize session for storage"""
|
|
|
|
| 39 |
"chat_history": [asdict(msg) for msg in self.app_instance.chat_history],
|
| 40 |
"session_state": asdict(self.app_instance.session_state),
|
| 41 |
"test_mode_active": self.app_instance.test_mode_active,
|
| 42 |
+
"current_test_patient": self.app_instance.current_test_patient,
|
| 43 |
+
"custom_prompts": self.custom_prompts,
|
| 44 |
+
"prompts_modified": self.prompts_modified
|
| 45 |
}
|
| 46 |
|
| 47 |
def update_activity(self):
|
| 48 |
"""Update last activity timestamp"""
|
| 49 |
self.last_activity = datetime.now().isoformat()
|
| 50 |
+
|
| 51 |
+
def set_custom_prompt(self, prompt_name: str, prompt_text: str):
|
| 52 |
+
"""Set custom prompt for this session"""
|
| 53 |
+
self.custom_prompts[prompt_name] = prompt_text
|
| 54 |
+
self.prompts_modified = True
|
| 55 |
+
# Update the app instance to use custom prompt
|
| 56 |
+
if hasattr(self.app_instance, 'main_lifestyle_assistant'):
|
| 57 |
+
self.app_instance.main_lifestyle_assistant.set_custom_system_prompt(prompt_text)
|
| 58 |
+
|
| 59 |
+
def reset_prompt_to_default(self, prompt_name: str):
|
| 60 |
+
"""Reset prompt to default"""
|
| 61 |
+
if prompt_name == "main_lifestyle":
|
| 62 |
+
self.custom_prompts[prompt_name] = SYSTEM_PROMPT_MAIN_LIFESTYLE
|
| 63 |
+
self.prompts_modified = False
|
| 64 |
+
# Update the app instance
|
| 65 |
+
if hasattr(self.app_instance, 'main_lifestyle_assistant'):
|
| 66 |
+
self.app_instance.main_lifestyle_assistant.reset_to_default_prompt()
|
| 67 |
|
| 68 |
def load_instructions() -> str:
|
| 69 |
"""Load instructions from INSTRUCTION.md file"""
|
|
|
|
| 102 |
"""
|
| 103 |
|
| 104 |
def create_session_isolated_interface():
|
| 105 |
+
"""Create session-isolated Gradio interface with Edit Prompts tab"""
|
| 106 |
|
| 107 |
log_prompts_enabled = os.getenv("LOG_PROMPTS", "false").lower() == "true"
|
| 108 |
|
|
|
|
| 124 |
|
| 125 |
# Header
|
| 126 |
if log_prompts_enabled:
|
| 127 |
+
gr.Markdown("# 🏥 Lifestyle Journey MVP + 🧪 Testing Lab + 🔧 Prompt Editor 📝")
|
| 128 |
gr.Markdown("⚠️ **DEBUG MODE:** LLM prompts and responses are saved to `lifestyle_journey.log`")
|
| 129 |
else:
|
| 130 |
+
gr.Markdown("# 🏥 Lifestyle Journey MVP + 🧪 Testing Lab + 🔧 Prompt Editor")
|
| 131 |
|
| 132 |
+
gr.Markdown("Medical chatbot with lifestyle coaching, testing system, and prompt customization")
|
| 133 |
|
| 134 |
# Session info
|
| 135 |
with gr.Row():
|
|
|
|
| 144 |
🆔 **Session ID:** `{new_session.session_id[:8]}...`
|
| 145 |
🕒 **Started:** {new_session.created_at[:19]}
|
| 146 |
👤 **Isolated Instance:** Each user has separate data
|
| 147 |
+
🔧 **Custom Prompts:** {'✅ Modified' if new_session.prompts_modified else '🔄 Default'}
|
| 148 |
"""
|
| 149 |
return new_session, session_info_text
|
| 150 |
|
|
|
|
| 189 |
refresh_status_btn = gr.Button("🔄 Refresh Status", size="sm")
|
| 190 |
|
| 191 |
end_conversation_result = gr.Markdown(value="", visible=False)
|
| 192 |
+
|
| 193 |
+
# NEW: Edit Prompts tab
|
| 194 |
+
with gr.TabItem("🔧 Edit Prompts", id="edit_prompts"):
|
| 195 |
+
gr.Markdown("## 🔧 Customize AI Assistant Prompts")
|
| 196 |
+
gr.Markdown("⚠️ **Note:** Changes apply only to your current session and will be lost when you close the browser.")
|
| 197 |
+
|
| 198 |
+
with gr.Row():
|
| 199 |
+
with gr.Column(scale=3):
|
| 200 |
+
gr.Markdown("### 💚 Main Lifestyle Assistant Prompt")
|
| 201 |
+
|
| 202 |
+
main_lifestyle_prompt = gr.Textbox(
|
| 203 |
+
label="System Prompt for Lifestyle Coaching",
|
| 204 |
+
value=SYSTEM_PROMPT_MAIN_LIFESTYLE,
|
| 205 |
+
lines=20,
|
| 206 |
+
max_lines=30,
|
| 207 |
+
placeholder="Enter your custom system prompt here...",
|
| 208 |
+
info="This prompt defines how the AI behaves during lifestyle coaching sessions."
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
with gr.Row():
|
| 212 |
+
apply_prompt_btn = gr.Button("✅ Apply Changes", variant="primary", scale=2)
|
| 213 |
+
reset_prompt_btn = gr.Button("🔄 Reset to Default", variant="secondary", scale=1)
|
| 214 |
+
preview_prompt_btn = gr.Button("👁️ Preview", size="sm", scale=1)
|
| 215 |
+
|
| 216 |
+
prompt_status = gr.Markdown(value="", visible=True)
|
| 217 |
+
|
| 218 |
+
with gr.Column(scale=1):
|
| 219 |
+
gr.Markdown("### 📋 Prompt Guidelines")
|
| 220 |
+
gr.Markdown("""
|
| 221 |
+
**🎯 Key Elements to Include:**
|
| 222 |
+
- **Role definition** (lifestyle coach)
|
| 223 |
+
- **Safety principles** (medical limitations)
|
| 224 |
+
- **Action logic** (gather_info/lifestyle_dialog/close)
|
| 225 |
+
- **Output format** (JSON with message/action/reasoning)
|
| 226 |
+
|
| 227 |
+
**⚠️ Important:**
|
| 228 |
+
- Keep JSON format for actions
|
| 229 |
+
- Maintain safety guidelines
|
| 230 |
+
- Consider patient's medical conditions
|
| 231 |
+
- Use same language as patient
|
| 232 |
+
|
| 233 |
+
**🔧 Actions:**
|
| 234 |
+
- `gather_info` - collect more details
|
| 235 |
+
- `lifestyle_dialog` - provide coaching
|
| 236 |
+
- `close` - end session safely
|
| 237 |
+
|
| 238 |
+
**💡 Tips:**
|
| 239 |
+
- Test changes with simple questions
|
| 240 |
+
- Use "🔄 Reset" if issues occur
|
| 241 |
+
- Check JSON format carefully
|
| 242 |
+
""")
|
| 243 |
+
|
| 244 |
+
gr.Markdown("### 📊 Current Settings")
|
| 245 |
+
prompt_info = gr.Markdown(value="🔄 Default prompt active")
|
| 246 |
|
| 247 |
# Testing Lab tab
|
| 248 |
with gr.TabItem("🧪 Testing Lab", id="testing_lab"):
|
|
|
|
| 309 |
value=[]
|
| 310 |
)
|
| 311 |
|
| 312 |
+
# Instructions tab
|
| 313 |
with gr.TabItem("📖 Instructions", id="instructions"):
|
| 314 |
gr.Markdown("## 📚 User Guide")
|
| 315 |
|
|
|
|
| 330 |
medical_example_btn = gr.Button("🩺 Medical Example", size="sm")
|
| 331 |
lifestyle_example_btn = gr.Button("💚 Lifestyle Example", size="sm")
|
| 332 |
testing_example_btn = gr.Button("🧪 Testing", size="sm")
|
| 333 |
+
prompts_example_btn = gr.Button("🔧 Edit Prompts", size="sm")
|
| 334 |
|
| 335 |
gr.Markdown("### 📞 Help")
|
| 336 |
refresh_instructions_btn = gr.Button("🔄 Refresh Instructions", size="sm")
|
|
|
|
| 394 |
|
| 395 |
session.update_activity()
|
| 396 |
base_status = session.app_instance._get_status_info()
|
| 397 |
+
|
| 398 |
+
# Add prompt status
|
| 399 |
+
prompt_status = ""
|
| 400 |
+
if session.prompts_modified:
|
| 401 |
+
prompt_status = f"""
|
| 402 |
+
🔧 **CUSTOM PROMPTS:**
|
| 403 |
+
• Main Lifestyle: ✅ Modified ({len(session.custom_prompts.get('main_lifestyle', ''))} chars)
|
| 404 |
+
• Status: Custom prompt active for this session
|
| 405 |
+
"""
|
| 406 |
+
else:
|
| 407 |
+
prompt_status = f"""
|
| 408 |
+
🔧 **CUSTOM PROMPTS:**
|
| 409 |
+
• Main Lifestyle: 🔄 Default prompt
|
| 410 |
+
• Status: Using original system prompts
|
| 411 |
+
"""
|
| 412 |
+
|
| 413 |
session_status = f"""
|
| 414 |
🔐 **SESSION ISOLATION:**
|
| 415 |
• Session ID: {session.session_id[:8]}...
|
| 416 |
• Created: {session.created_at[:19]}
|
| 417 |
• Last Activity: {session.last_activity[:19]}
|
| 418 |
• Isolated: ✅ Your data is private
|
| 419 |
+
{prompt_status}
|
| 420 |
{base_status}
|
| 421 |
"""
|
| 422 |
return session_status
|
| 423 |
|
| 424 |
+
# NEW: Prompt editing handlers
|
| 425 |
+
def apply_custom_prompt(prompt_text: str, session: SessionData):
|
| 426 |
+
"""Apply custom prompt to session"""
|
| 427 |
+
if session is None:
|
| 428 |
+
session = SessionData()
|
| 429 |
+
|
| 430 |
+
session.update_activity()
|
| 431 |
+
|
| 432 |
+
# Validate prompt (basic check)
|
| 433 |
+
if not prompt_text.strip():
|
| 434 |
+
return "❌ Prompt cannot be empty", session, "❌ Empty prompt"
|
| 435 |
+
|
| 436 |
+
if len(prompt_text.strip()) < 50:
|
| 437 |
+
return "⚠️ Prompt seems too short. Are you sure it's complete?", session, "⚠️ Short prompt"
|
| 438 |
+
|
| 439 |
+
try:
|
| 440 |
+
# Apply the custom prompt
|
| 441 |
+
session.set_custom_prompt("main_lifestyle", prompt_text.strip())
|
| 442 |
+
|
| 443 |
+
status_msg = f"""✅ **Custom prompt applied successfully!**
|
| 444 |
+
|
| 445 |
+
📊 **Details:**
|
| 446 |
+
• Length: {len(prompt_text.strip())} characters
|
| 447 |
+
• Applied to: Main Lifestyle Assistant
|
| 448 |
+
• Session: {session.session_id[:8]}...
|
| 449 |
+
• Status: Active for this session only
|
| 450 |
+
|
| 451 |
+
🔄 **Next steps:**
|
| 452 |
+
• Test the changes by starting a lifestyle conversation
|
| 453 |
+
• Use "Reset to Default" if you encounter issues
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
info_msg = f"✅ Custom prompt active ({len(prompt_text.strip())} chars)"
|
| 457 |
+
|
| 458 |
+
return status_msg, session, info_msg
|
| 459 |
+
|
| 460 |
+
except Exception as e:
|
| 461 |
+
error_msg = f"❌ Error applying prompt: {str(e)}"
|
| 462 |
+
return error_msg, session, "❌ Application failed"
|
| 463 |
+
|
| 464 |
+
def reset_prompt_to_default(session: SessionData):
|
| 465 |
+
"""Reset prompt to default"""
|
| 466 |
+
if session is None:
|
| 467 |
+
session = SessionData()
|
| 468 |
+
|
| 469 |
+
session.update_activity()
|
| 470 |
+
session.reset_prompt_to_default("main_lifestyle")
|
| 471 |
+
|
| 472 |
+
status_msg = f"""🔄 **Prompt reset to default**
|
| 473 |
+
|
| 474 |
+
📊 **Details:**
|
| 475 |
+
• Main Lifestyle Assistant prompt restored
|
| 476 |
+
• Session: {session.session_id[:8]}...
|
| 477 |
+
• All customizations removed
|
| 478 |
+
|
| 479 |
+
💡 You can edit and apply again at any time.
|
| 480 |
+
"""
|
| 481 |
+
|
| 482 |
+
return SYSTEM_PROMPT_MAIN_LIFESTYLE, status_msg, session, "🔄 Default prompt active"
|
| 483 |
+
|
| 484 |
+
def preview_prompt_changes(prompt_text: str):
|
| 485 |
+
"""Preview prompt changes"""
|
| 486 |
+
if not prompt_text.strip():
|
| 487 |
+
return "❌ No prompt text to preview"
|
| 488 |
+
|
| 489 |
+
preview = f"""📋 **Prompt Preview:**
|
| 490 |
+
|
| 491 |
+
**Length:** {len(prompt_text.strip())} characters
|
| 492 |
+
**Lines:** {len(prompt_text.strip().split(chr(10)))} lines
|
| 493 |
+
|
| 494 |
+
**First 200 characters:**
|
| 495 |
+
```
|
| 496 |
+
{prompt_text.strip()[:200]}{'...' if len(prompt_text.strip()) > 200 else ''}
|
| 497 |
+
```
|
| 498 |
+
|
| 499 |
+
**Contains key elements:**
|
| 500 |
+
• JSON format mentioned: {'✅' if 'json' in prompt_text.lower() or 'JSON' in prompt_text else '❌'}
|
| 501 |
+
• Actions mentioned: {'✅' if 'gather_info' in prompt_text and 'lifestyle_dialog' in prompt_text and 'close' in prompt_text else '❌'}
|
| 502 |
+
• Safety guidelines: {'✅' if 'safety' in prompt_text.lower() or 'medical' in prompt_text.lower() else '❌'}
|
| 503 |
+
|
| 504 |
+
**Ready to apply:** {'✅ Yes' if len(prompt_text.strip()) > 50 else '❌ Too short'}
|
| 505 |
+
"""
|
| 506 |
+
return preview
|
| 507 |
+
|
| 508 |
# Helper functions for examples and instructions
|
| 509 |
def send_example_message(example_text: str, history, session: SessionData):
|
| 510 |
"""Send example message to chat"""
|
|
|
|
| 585 |
outputs=[status_box]
|
| 586 |
)
|
| 587 |
|
| 588 |
+
# NEW: Prompt editing events
|
| 589 |
+
apply_prompt_btn.click(
|
| 590 |
+
apply_custom_prompt,
|
| 591 |
+
inputs=[main_lifestyle_prompt, session_data],
|
| 592 |
+
outputs=[prompt_status, session_data, prompt_info]
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
reset_prompt_btn.click(
|
| 596 |
+
reset_prompt_to_default,
|
| 597 |
+
inputs=[session_data],
|
| 598 |
+
outputs=[main_lifestyle_prompt, prompt_status, session_data, prompt_info]
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
preview_prompt_btn.click(
|
| 602 |
+
preview_prompt_changes,
|
| 603 |
+
inputs=[main_lifestyle_prompt],
|
| 604 |
+
outputs=[prompt_status]
|
| 605 |
+
)
|
| 606 |
+
|
| 607 |
# Quick example buttons in chat
|
| 608 |
example_medical_btn.click(
|
| 609 |
lambda history, session: send_example_message("I have a headache", history, session),
|
|
|
|
| 645 |
outputs=[]
|
| 646 |
)
|
| 647 |
|
| 648 |
+
prompts_example_btn.click(
|
| 649 |
+
lambda: gr.update(selected="edit_prompts"), # Switch to prompts tab
|
| 650 |
+
outputs=[]
|
| 651 |
+
)
|
| 652 |
+
|
| 653 |
# Testing Lab handlers with session isolation
|
| 654 |
load_patient_btn.click(
|
| 655 |
handle_load_patient_isolated,
|
lifestyle_app.py
CHANGED
|
@@ -675,4 +675,28 @@ Your progress and preferences have been recorded for future sessions."""
|
|
| 675 |
entry_classification={}
|
| 676 |
)
|
| 677 |
|
| 678 |
-
return [], self._get_status_info(), result_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
entry_classification={}
|
| 676 |
)
|
| 677 |
|
| 678 |
+
return [], self._get_status_info(), result_message
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
def sync_custom_prompts_from_session(self, session_data):
|
| 682 |
+
"""Синхронізує кастомні промпти з SessionData"""
|
| 683 |
+
from prompts import SYSTEM_PROMPT_MAIN_LIFESTYLE
|
| 684 |
+
|
| 685 |
+
if hasattr(session_data, 'custom_prompts') and session_data.custom_prompts:
|
| 686 |
+
main_lifestyle_prompt = session_data.custom_prompts.get('main_lifestyle')
|
| 687 |
+
if main_lifestyle_prompt and main_lifestyle_prompt != SYSTEM_PROMPT_MAIN_LIFESTYLE:
|
| 688 |
+
self.main_lifestyle_assistant.set_custom_system_prompt(main_lifestyle_prompt)
|
| 689 |
+
else:
|
| 690 |
+
self.main_lifestyle_assistant.reset_to_default_prompt()
|
| 691 |
+
|
| 692 |
+
def get_current_prompt_info(self) -> Dict[str, str]:
|
| 693 |
+
"""Отримує інформацію про поточні промпти"""
|
| 694 |
+
current_prompt = self.main_lifestyle_assistant.get_current_system_prompt()
|
| 695 |
+
is_custom = self.main_lifestyle_assistant.custom_system_prompt is not None
|
| 696 |
+
|
| 697 |
+
return {
|
| 698 |
+
"is_custom": is_custom,
|
| 699 |
+
"prompt_length": len(current_prompt),
|
| 700 |
+
"prompt_preview": current_prompt[:100] + "..." if len(current_prompt) > 100 else current_prompt,
|
| 701 |
+
"status": "Custom prompt active" if is_custom else "Default prompt active"
|
| 702 |
+
}
|
lifestyle_profile.json
CHANGED
|
@@ -9,44 +9,16 @@
|
|
| 9 |
"Chronic venous insufficiency",
|
| 10 |
"Sedentary lifestyle syndrome"
|
| 11 |
],
|
| 12 |
-
"primary_goal": "Achieve gradual, medically-supervised weight reduction and cardiovascular fitness improvement while safely managing anticoagulation therapy and post-thrombotic recovery. *Immediate priority: Medical review of new DVT test results and adjustment of treatment plan if necessary, followed by integration of lifestyle coaching recommendations.*",
|
| 13 |
-
"exercise_preferences": [
|
| 14 |
-
"swimming (currently 20 mins twice weekly, feels good post-activity)",
|
| 15 |
-
"aquatic therapy/water walking",
|
| 16 |
-
"stationary cycling",
|
| 17 |
-
"gentle yoga",
|
| 18 |
-
"walking (with compression stockings for prolonged activity, short walks without issues)",
|
| 19 |
-
"resistance training with light weights"
|
| 20 |
-
],
|
| 21 |
"exercise_limitations": [
|
| 22 |
-
"
|
| 23 |
-
"Recent DVT right leg - requires graduated compression during prolonged activity (>2 hours on feet), short walks (30 mins) without issues reported, medical review of new DVT data is paramount",
|
| 24 |
-
"Post-ablation cardiac monitoring recommended for exercise initiation",
|
| 25 |
-
"Severe obesity limits weight-bearing activities initially, extremely gradual progression required",
|
| 26 |
-
"Must monitor for signs of bleeding, chest pain, or leg swelling",
|
| 27 |
-
"Computer work schedule limits exercise time to early morning or evening"
|
| 28 |
-
],
|
| 29 |
-
"dietary_notes": [
|
| 30 |
-
"Weight management critical - structured calorie reduction needed",
|
| 31 |
-
"Heart-healthy Mediterranean-style diet recommended",
|
| 32 |
-
"Consistent Vitamin K intake due to anticoagulation",
|
| 33 |
-
"Reduce caffeine from 4-5 cups coffee to 2-3 cups daily",
|
| 34 |
-
"Increase anti-inflammatory foods",
|
| 35 |
-
"Portion control education needed",
|
| 36 |
-
"Meal prep strategies for busy academic schedule"
|
| 37 |
-
],
|
| 38 |
-
"personal_preferences": [
|
| 39 |
-
"intellectually curious - wants to understand physiological mechanisms",
|
| 40 |
-
"data-driven approach - enjoys tracking metrics and progress",
|
| 41 |
-
"prefers evidence-based recommendations",
|
| 42 |
-
"swimming nostalgia - strong positive association with water activities",
|
| 43 |
-
"values efficiency - wants maximum benefit from limited exercise time",
|
| 44 |
-
"academic schedule flexibility - can adjust timing for optimal health",
|
| 45 |
-
"prefers solo activities that allow thinking/problem-solving"
|
| 46 |
],
|
| 47 |
-
"
|
| 48 |
-
"
|
| 49 |
-
"
|
|
|
|
|
|
|
| 50 |
"progress_metrics": {
|
| 51 |
"baseline_weight": "120.0 kg (target: gradual reduction to 95-100 kg)",
|
| 52 |
"baseline_bmi": "36.7 (target: <30, eventually <25)",
|
|
|
|
| 9 |
"Chronic venous insufficiency",
|
| 10 |
"Sedentary lifestyle syndrome"
|
| 11 |
],
|
| 12 |
+
"primary_goal": "Achieve gradual, medically-supervised weight reduction and cardiovascular fitness improvement while safely managing anticoagulation therapy and post-thrombotic recovery. *Immediate priority: Medical evaluation of new headache symptom, medical review of new DVT test results, and adjustment of treatment plan if necessary, followed by integration of lifestyle coaching recommendations once medically cleared.*",
|
| 13 |
+
"exercise_preferences": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"exercise_limitations": [
|
| 15 |
+
"New symptom (headache) reported, requiring immediate medical evaluation before any exercise recommendations can be made or existing activity levels adjusted. This temporarily supersedes previous exercise considerations."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
],
|
| 17 |
+
"dietary_notes": [],
|
| 18 |
+
"personal_preferences": [],
|
| 19 |
+
"journey_summary": "Computer science professor with recent serious cardiovascular events requiring major lifestyle intervention. Successfully underwent atrial fibrillation ablation in August 2024 with good results. Developed DVT in June 2025, highlighting the urgency of addressing sedentary lifestyle and obesity. Former competitive swimmer with muscle memory and positive association with aquatic exercise. Currently stable on medications but requires careful, progressive approach to lifestyle changes due to anticoagulation and thrombotic history. | 05.09.2025: Serhii is highly motivated and has already initiated positive lifestyle changes (weight loss, swimmi... | 05.09.2025: Serhii is motivated and compliant with his current exercise regimen, showing initial weight loss. Hi... | 05.09.2025: The patient's motivation to 'start exercising' is high, indicating readiness for lifestyle changes o...",
|
| 20 |
+
"last_session_summary": "[05.09.2025] Session ended prematurely due to patient reporting a new headache symptom. Patient expressed a desire to start exercising. No new lifestyle recommendations were provided. The immediate priority is medical evaluation of the headache and pending DVT test results.",
|
| 21 |
+
"next_check_in": "Immediate follow-up (1-3 days)",
|
| 22 |
"progress_metrics": {
|
| 23 |
"baseline_weight": "120.0 kg (target: gradual reduction to 95-100 kg)",
|
| 24 |
"baseline_bmi": "36.7 (target: <30, eventually <25)",
|
lifestyle_profile.json.backup
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"patient_name": "Serhii",
|
| 3 |
+
"patient_age": "52",
|
| 4 |
+
"conditions": [
|
| 5 |
+
"Atrial fibrillation (post-ablation August 2024)",
|
| 6 |
+
"Deep vein thrombosis right leg (June 2025)",
|
| 7 |
+
"Severe obesity (BMI 36.7)",
|
| 8 |
+
"Hypertension (controlled)",
|
| 9 |
+
"Chronic venous insufficiency",
|
| 10 |
+
"Sedentary lifestyle syndrome"
|
| 11 |
+
],
|
| 12 |
+
"primary_goal": "Achieve gradual, medically-supervised weight reduction and cardiovascular fitness improvement while safely managing anticoagulation therapy and post-thrombotic recovery. *Immediate priority: Medical review of new DVT test results and adjustment of treatment plan if necessary, followed by integration of lifestyle coaching recommendations.*",
|
| 13 |
+
"exercise_preferences": [
|
| 14 |
+
"swimming (currently 20 mins twice weekly, feels good post-activity)",
|
| 15 |
+
"aquatic therapy/water walking",
|
| 16 |
+
"stationary cycling",
|
| 17 |
+
"gentle yoga",
|
| 18 |
+
"walking (with compression stockings for prolonged activity, short walks without issues)",
|
| 19 |
+
"resistance training with light weights"
|
| 20 |
+
],
|
| 21 |
+
"exercise_limitations": [
|
| 22 |
+
"On anticoagulation therapy - avoid contact sports and high fall-risk activities",
|
| 23 |
+
"Recent DVT right leg - requires graduated compression during prolonged activity (>2 hours on feet), short walks (30 mins) without issues reported, medical review of new DVT data is paramount",
|
| 24 |
+
"Post-ablation cardiac monitoring recommended for exercise initiation",
|
| 25 |
+
"Severe obesity limits weight-bearing activities initially, extremely gradual progression required",
|
| 26 |
+
"Must monitor for signs of bleeding, chest pain, or leg swelling",
|
| 27 |
+
"Computer work schedule limits exercise time to early morning or evening"
|
| 28 |
+
],
|
| 29 |
+
"dietary_notes": [
|
| 30 |
+
"Weight management critical - structured calorie reduction needed",
|
| 31 |
+
"Heart-healthy Mediterranean-style diet recommended",
|
| 32 |
+
"Consistent Vitamin K intake due to anticoagulation",
|
| 33 |
+
"Reduce caffeine from 4-5 cups coffee to 2-3 cups daily",
|
| 34 |
+
"Increase anti-inflammatory foods",
|
| 35 |
+
"Portion control education needed",
|
| 36 |
+
"Meal prep strategies for busy academic schedule"
|
| 37 |
+
],
|
| 38 |
+
"personal_preferences": [
|
| 39 |
+
"intellectually curious - wants to understand physiological mechanisms",
|
| 40 |
+
"data-driven approach - enjoys tracking metrics and progress",
|
| 41 |
+
"prefers evidence-based recommendations",
|
| 42 |
+
"swimming nostalgia - strong positive association with water activities",
|
| 43 |
+
"values efficiency - wants maximum benefit from limited exercise time",
|
| 44 |
+
"academic schedule flexibility - can adjust timing for optimal health",
|
| 45 |
+
"prefers solo activities that allow thinking/problem-solving"
|
| 46 |
+
],
|
| 47 |
+
"journey_summary": "Computer science professor with recent serious cardiovascular events requiring major lifestyle intervention. Successfully underwent atrial fibrillation ablation in August 2024 with good results. Developed DVT in June 2025, highlighting the urgency of addressing sedentary lifestyle and obesity. Former competitive swimmer with muscle memory and positive association with aquatic exercise. Currently stable on medications but requires careful, progressive approach to lifestyle changes due to anticoagulation and thrombotic history. | 05.09.2025: Serhii is highly motivated and has already initiated positive lifestyle changes (weight loss, swimmi... | 05.09.2025: Serhii is motivated and compliant with his current exercise regimen, showing initial weight loss. Hi...",
|
| 48 |
+
"last_session_summary": "[05.09.2025] Patient reported current weight of 118 kg, confirming initial weight loss. He is consistently swimming 20 minutes twice weekly and feels well post-activity. Clarified that compression stockings are used for prolonged activity (>2 hours) but not immediately after swimming or for short 30-minute evening walks, which he tolerates without discomfort. The critical medical review of new DVT test results remains pending and is a prerequisite for further detailed lifestyle recommendations.",
|
| 49 |
+
"next_check_in": "As needed, after medical review and updated guidance from treating physician.",
|
| 50 |
+
"progress_metrics": {
|
| 51 |
+
"baseline_weight": "120.0 kg (target: gradual reduction to 95-100 kg)",
|
| 52 |
+
"baseline_bmi": "36.7 (target: <30, eventually <25)",
|
| 53 |
+
"baseline_bp": "128/82 (well controlled on medication)",
|
| 54 |
+
"current_exercise_frequency": "2 times per week (swimming 20 mins each session), plus short evening walks (30 mins) without discomfort",
|
| 55 |
+
"daily_steps": "approximately 1,500-2,000 steps (computer to car to home)",
|
| 56 |
+
"swimming_background": "competitive swimmer age 18-22 (1990-1994), excellent technique retained",
|
| 57 |
+
"anticoagulation_status": "therapeutic on Xarelto, INR 2.1",
|
| 58 |
+
"dvt_recovery": "improving, compression therapy compliant for prolonged activity, short walks tolerated without stockings, but new medical data requires review and may impact recommendations",
|
| 59 |
+
"cardiac_rhythm": "stable sinus rhythm post-ablation",
|
| 60 |
+
"motivation_level": "high - recent health scares provided strong motivation",
|
| 61 |
+
"academic_schedule": "semester-based, some flexibility for health priorities",
|
| 62 |
+
"current_weight": "118.0 kg (down from 120 kg)"
|
| 63 |
+
}
|
| 64 |
+
}
|