|
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): |
|
|
|
final_language = custom_language if output_language == "Other" else output_language |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
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) |
|
|
|
|
|
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() |
|
|