ernani
commited on
Commit
·
146e092
1
Parent(s):
023b853
adding different language outputs support
Browse files
app.py
CHANGED
|
@@ -9,7 +9,10 @@ class FitnessProfileGUI:
|
|
| 9 |
|
| 10 |
def create_fitness_plan(self, age, weight, height, gender, primary_goal, target_timeframe,
|
| 11 |
workout_preferences, workout_duration, workout_days,
|
| 12 |
-
activity_level, health_conditions, dietary_preferences):
|
|
|
|
|
|
|
|
|
|
| 13 |
# Generate the fitness plan using the tools module
|
| 14 |
result = generate_fitness_plan(
|
| 15 |
age=age,
|
|
@@ -22,6 +25,7 @@ class FitnessProfileGUI:
|
|
| 22 |
workout_duration=workout_duration,
|
| 23 |
workout_days=workout_days,
|
| 24 |
activity_level=activity_level,
|
|
|
|
| 25 |
health_conditions=health_conditions,
|
| 26 |
dietary_preferences=dietary_preferences
|
| 27 |
)
|
|
@@ -36,6 +40,9 @@ FITNESS PLAN
|
|
| 36 |
"""
|
| 37 |
return output
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
def create_interface(self):
|
| 40 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 41 |
gr.Markdown("# AI Fitness Coach")
|
|
@@ -91,7 +98,14 @@ FITNESS PLAN
|
|
| 91 |
|
| 92 |
output_language = gr.Radio(
|
| 93 |
choices=["English", "Spanish", "French", "German", "Italian", "Portuguese", "Russian", "Arabic", "Chinese", "Japanese", "Korean", "Vietnamese", "Other"],
|
| 94 |
-
label="Output Language"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
activity_level = gr.Radio(
|
|
@@ -114,13 +128,20 @@ FITNESS PLAN
|
|
| 114 |
submit_btn = gr.Button("Generate Fitness Plan", variant="primary")
|
| 115 |
output = gr.Textbox(label="Generated Fitness Plan", lines=10)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
submit_btn.click(
|
| 118 |
fn=self.create_fitness_plan,
|
| 119 |
inputs=[
|
| 120 |
age, weight, height, gender,
|
| 121 |
primary_goal, target_timeframe,
|
| 122 |
workout_preferences, workout_duration,
|
| 123 |
-
workout_days, activity_level, output_language,
|
| 124 |
health_conditions, dietary_preferences
|
| 125 |
],
|
| 126 |
outputs=output
|
|
|
|
| 9 |
|
| 10 |
def create_fitness_plan(self, age, weight, height, gender, primary_goal, target_timeframe,
|
| 11 |
workout_preferences, workout_duration, workout_days,
|
| 12 |
+
activity_level, output_language, custom_language, health_conditions, dietary_preferences):
|
| 13 |
+
# If output_language is "Other", use the custom language instead
|
| 14 |
+
final_language = custom_language if output_language == "Other" else output_language
|
| 15 |
+
|
| 16 |
# Generate the fitness plan using the tools module
|
| 17 |
result = generate_fitness_plan(
|
| 18 |
age=age,
|
|
|
|
| 25 |
workout_duration=workout_duration,
|
| 26 |
workout_days=workout_days,
|
| 27 |
activity_level=activity_level,
|
| 28 |
+
output_language=final_language,
|
| 29 |
health_conditions=health_conditions,
|
| 30 |
dietary_preferences=dietary_preferences
|
| 31 |
)
|
|
|
|
| 40 |
"""
|
| 41 |
return output
|
| 42 |
|
| 43 |
+
def show_custom_language_input(self, output_language):
|
| 44 |
+
return gr.update(visible=output_language == "Other")
|
| 45 |
+
|
| 46 |
def create_interface(self):
|
| 47 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 48 |
gr.Markdown("# AI Fitness Coach")
|
|
|
|
| 98 |
|
| 99 |
output_language = gr.Radio(
|
| 100 |
choices=["English", "Spanish", "French", "German", "Italian", "Portuguese", "Russian", "Arabic", "Chinese", "Japanese", "Korean", "Vietnamese", "Other"],
|
| 101 |
+
label="Output Language",
|
| 102 |
+
value="English"
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
custom_language = gr.Textbox(
|
| 106 |
+
label="Specify Language",
|
| 107 |
+
placeholder="Enter your preferred language...",
|
| 108 |
+
visible=False
|
| 109 |
)
|
| 110 |
|
| 111 |
activity_level = gr.Radio(
|
|
|
|
| 128 |
submit_btn = gr.Button("Generate Fitness Plan", variant="primary")
|
| 129 |
output = gr.Textbox(label="Generated Fitness Plan", lines=10)
|
| 130 |
|
| 131 |
+
# Add event handler for language selection
|
| 132 |
+
output_language.change(
|
| 133 |
+
fn=self.show_custom_language_input,
|
| 134 |
+
inputs=[output_language],
|
| 135 |
+
outputs=[custom_language]
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
submit_btn.click(
|
| 139 |
fn=self.create_fitness_plan,
|
| 140 |
inputs=[
|
| 141 |
age, weight, height, gender,
|
| 142 |
primary_goal, target_timeframe,
|
| 143 |
workout_preferences, workout_duration,
|
| 144 |
+
workout_days, activity_level, output_language, custom_language,
|
| 145 |
health_conditions, dietary_preferences
|
| 146 |
],
|
| 147 |
outputs=output
|
tools.py
CHANGED
|
@@ -215,6 +215,8 @@ def generate_fitness_plan(
|
|
| 215 |
workout_duration: int,
|
| 216 |
workout_days: List[str],
|
| 217 |
activity_level: str,
|
|
|
|
|
|
|
| 218 |
health_conditions: str,
|
| 219 |
dietary_preferences: str
|
| 220 |
) -> Dict:
|
|
@@ -224,6 +226,9 @@ def generate_fitness_plan(
|
|
| 224 |
bmi = calculate_bmi(weight, height)
|
| 225 |
bmi_category = get_bmi_category(bmi)
|
| 226 |
|
|
|
|
|
|
|
|
|
|
| 227 |
# Create a profile summary
|
| 228 |
profile_summary = f"""
|
| 229 |
User Profile:
|
|
@@ -231,6 +236,7 @@ def generate_fitness_plan(
|
|
| 231 |
- Gender: {gender}
|
| 232 |
- BMI: {bmi:.1f} ({bmi_category})
|
| 233 |
- Activity Level: {activity_level}
|
|
|
|
| 234 |
- Primary Goal: {primary_goal}
|
| 235 |
- Target Timeframe: {target_timeframe}
|
| 236 |
- Preferred Workout Types: {', '.join(workout_preferences)}
|
|
@@ -247,7 +253,7 @@ def generate_fitness_plan(
|
|
| 247 |
)
|
| 248 |
|
| 249 |
# Create the prompt for generating the fitness plan
|
| 250 |
-
system_prompt = """You are an expert fitness trainer and nutritionist. Your task is to create a detailed,
|
| 251 |
personalized fitness plan based on the user's profile. The plan should include:
|
| 252 |
|
| 253 |
1. Weekly workout schedule - detailed information of the warmup option ( if it's HIIT, suggest one, for example, duration, intensity, and type of exercise )
|
|
@@ -257,9 +263,12 @@ def generate_fitness_plan(
|
|
| 257 |
5. Safety considerations and modifications
|
| 258 |
6. Progress tracking metrics
|
| 259 |
7. Warmup, strength training, cardio, and cool down
|
| 260 |
-
|
| 261 |
Consider the user's current fitness level, goals, preferences, and any health conditions when creating the plan.
|
| 262 |
-
Make the plan realistic and achievable within their target timeframe.
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
# Generate the fitness plan
|
| 265 |
messages = [
|
|
|
|
| 215 |
workout_duration: int,
|
| 216 |
workout_days: List[str],
|
| 217 |
activity_level: str,
|
| 218 |
+
output_language: str,
|
| 219 |
+
custom_language: str,
|
| 220 |
health_conditions: str,
|
| 221 |
dietary_preferences: str
|
| 222 |
) -> Dict:
|
|
|
|
| 226 |
bmi = calculate_bmi(weight, height)
|
| 227 |
bmi_category = get_bmi_category(bmi)
|
| 228 |
|
| 229 |
+
if output_language == "Other":
|
| 230 |
+
output_language = custom_language
|
| 231 |
+
|
| 232 |
# Create a profile summary
|
| 233 |
profile_summary = f"""
|
| 234 |
User Profile:
|
|
|
|
| 236 |
- Gender: {gender}
|
| 237 |
- BMI: {bmi:.1f} ({bmi_category})
|
| 238 |
- Activity Level: {activity_level}
|
| 239 |
+
- Output Language: {output_language}
|
| 240 |
- Primary Goal: {primary_goal}
|
| 241 |
- Target Timeframe: {target_timeframe}
|
| 242 |
- Preferred Workout Types: {', '.join(workout_preferences)}
|
|
|
|
| 253 |
)
|
| 254 |
|
| 255 |
# Create the prompt for generating the fitness plan
|
| 256 |
+
system_prompt = f"""You are an expert fitness trainer and nutritionist. Your task is to create a detailed,
|
| 257 |
personalized fitness plan based on the user's profile. The plan should include:
|
| 258 |
|
| 259 |
1. Weekly workout schedule - detailed information of the warmup option ( if it's HIIT, suggest one, for example, duration, intensity, and type of exercise )
|
|
|
|
| 263 |
5. Safety considerations and modifications
|
| 264 |
6. Progress tracking metrics
|
| 265 |
7. Warmup, strength training, cardio, and cool down
|
| 266 |
+
|
| 267 |
Consider the user's current fitness level, goals, preferences, and any health conditions when creating the plan.
|
| 268 |
+
Make the plan realistic and achievable within their target timeframe.
|
| 269 |
+
|
| 270 |
+
IMPORTANT: Please provide the entire response in {output_language}. Make sure all instructions,
|
| 271 |
+
explanations, and recommendations are written in {output_language}."""
|
| 272 |
|
| 273 |
# Generate the fitness plan
|
| 274 |
messages = [
|