File size: 6,850 Bytes
675e74d 0955862 bc80a58 675e74d bc80a58 0955862 675e74d bc80a58 146e092 bc80a58 146e092 bc80a58 675e74d bc80a58 675e74d 146e092 bc80a58 0955862 bc80a58 023b853 0955862 bc80a58 023b853 146e092 023b853 bc80a58 146e092 bc80a58 146e092 bc80a58 0955862 675e74d 0955862 675e74d bc80a58 |
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 |
import gradio as gr
import os
from tools import generate_fitness_plan
class FitnessProfileGUI:
def __init__(self, share=False):
self.share = share
self.demo = self.create_interface()
def create_fitness_plan(self, age, weight, height, gender, primary_goal, target_timeframe,
workout_preferences, workout_duration, workout_days,
activity_level, output_language, custom_language, health_conditions, dietary_preferences):
# If output_language is "Other", use the custom language instead
final_language = custom_language if output_language == "Other" else output_language
# Generate the fitness plan using the tools module
result = generate_fitness_plan(
age=age,
weight=weight,
height=height,
gender=gender,
primary_goal=primary_goal,
target_timeframe=target_timeframe,
workout_preferences=workout_preferences,
workout_duration=workout_duration,
workout_days=workout_days,
activity_level=activity_level,
output_language=final_language,
health_conditions=health_conditions,
dietary_preferences=dietary_preferences
)
# Format the output
output = f"""
{result['profile_summary']}
FITNESS PLAN
===========
{result['fitness_plan']}
"""
return output
def show_custom_language_input(self, output_language):
return gr.update(visible=output_language == "Other")
def create_interface(self):
with gr.Blocks(theme=gr.themes.Default()) as demo:
gr.Markdown("# AI Fitness Coach")
with gr.Tabs():
with gr.Tab("Create Fitness Plan - Workout"):
with gr.Row():
age = gr.Number(label="Age", value=0)
weight = gr.Number(label="Weight (kg)", value=0)
height = gr.Number(label="Height (cm)", value=0)
gender = gr.Radio(choices=["Male", "Female"], label="Gender")
primary_goal = gr.Dropdown(
choices=[
"Weight Loss",
"Muscle Gain",
"Strength Building",
"General Fitness",
"Endurance Improvement",
"Flexibility Enhancement"
],
label="Primary Goal"
)
target_timeframe = gr.Dropdown(
choices=[
"1 month",
"3 months",
"6 months",
"1 year",
"Ongoing"
],
label="Target Timeframe"
)
workout_preferences = gr.CheckboxGroup(
choices=["Cardio", "Strength training", "Yoga", "Pilates", "Flexibility exercises", "HIIT"],
label="Workout Type Preferences"
)
workout_duration = gr.Slider(
minimum=15,
maximum=120,
step=15,
label="Preferred Workout Duration (minutes)",
value=15
)
workout_days = gr.CheckboxGroup(
choices=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
label="Preferred Workout Days"
)
output_language = gr.Radio(
choices=["English", "Spanish", "French", "German", "Italian", "Portuguese", "Russian", "Arabic", "Chinese", "Japanese", "Korean", "Vietnamese", "Other"],
label="Output Language",
value="English"
)
custom_language = gr.Textbox(
label="Specify Language",
placeholder="Enter your preferred language...",
visible=False
)
activity_level = gr.Radio(
choices=["Sedentary", "Lightly active", "Moderately active", "Highly active"],
label="Current Activity Level"
)
health_conditions = gr.Textbox(
label="Health Conditions or Injuries",
placeholder="List any health conditions, injuries, or limitations...",
lines=3
)
dietary_preferences = gr.Textbox(
label="Dietary Preferences (Optional)",
placeholder="List any dietary preferences or restrictions...",
lines=3
)
submit_btn = gr.Button("Generate Fitness Plan", variant="primary")
output = gr.Textbox(label="Generated Fitness Plan", lines=10)
# Add event handler for language selection
output_language.change(
fn=self.show_custom_language_input,
inputs=[output_language],
outputs=[custom_language]
)
submit_btn.click(
fn=self.create_fitness_plan,
inputs=[
age, weight, height, gender,
primary_goal, target_timeframe,
workout_preferences, workout_duration,
workout_days, activity_level, output_language, custom_language,
health_conditions, dietary_preferences
],
outputs=output
)
with gr.Tab("Update Fitness Plan"):
gr.Markdown("Coming soon: Update your existing fitness plan")
return demo
def launch(self, share=None):
if port := os.getenv("PORT1"):
self.demo.launch(share=True, server_port=int(port), server_name="0.0.0.0")
else:
self.demo.launch(share=self.share)
if __name__ == "__main__":
fitness_profile = FitnessProfileGUI()
fitness_profile.launch()
|