Upload 2 files
Browse files- app.py +100 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
# PAGE 1: Daily Plan Generator
|
| 6 |
+
def generate_daily_plan(wake_time, swim_duration, gym_today, sleep_hours, goal):
|
| 7 |
+
plan = []
|
| 8 |
+
if sleep_hours < 7:
|
| 9 |
+
plan.append("β οΈ Less than 7 hours of sleep β consider adjusting recovery.")
|
| 10 |
+
plan.append(f"π
Wake at {wake_time}")
|
| 11 |
+
plan.append(f"πββοΈ Swim: {swim_duration} min β Focus: {goal}")
|
| 12 |
+
if gym_today:
|
| 13 |
+
plan.append("ποΈββοΈ Gym: Yes β tailor to today's goal")
|
| 14 |
+
else:
|
| 15 |
+
plan.append("πͺ Gym: Rest or mobility work")
|
| 16 |
+
plan.append("π½οΈ Nutrition: Eat protein + carbs within 30 min post-swim")
|
| 17 |
+
plan.append("π Sleep target: 8+ hours")
|
| 18 |
+
return "\n".join(plan)
|
| 19 |
+
|
| 20 |
+
daily_plan = gr.Interface(
|
| 21 |
+
fn=generate_daily_plan,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Textbox(label="Wake Time (e.g. 5:30 AM)"),
|
| 24 |
+
gr.Slider(label="Swim Duration (min)", minimum=0, maximum=180),
|
| 25 |
+
gr.Checkbox(label="Gym Today?"),
|
| 26 |
+
gr.Slider(label="Sleep Last Night (hrs)", minimum=4, maximum=10, step=0.5),
|
| 27 |
+
gr.Dropdown(["speed", "endurance", "technique", "recovery"], label="Today's Goal")
|
| 28 |
+
],
|
| 29 |
+
outputs=gr.Textbox(label="AI Daily Plan"),
|
| 30 |
+
title="π§ SwimCoach+ AI β Daily Plan"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# PAGE 2: Nutrition and Sleep Tracker (placeholder)
|
| 34 |
+
def diet_sleep_tracker(sleep, image=None, food_name=""):
|
| 35 |
+
feedback = f"π Sleep: {sleep} hrs β "
|
| 36 |
+
feedback += "Great recovery!" if sleep >= 8 else "Try to get more rest tonight."
|
| 37 |
+
if image:
|
| 38 |
+
feedback += "\nπ½οΈ Food: [AI Image Analysis Coming Soon]"
|
| 39 |
+
elif food_name:
|
| 40 |
+
feedback += f"\nπ½οΈ Food entered: {food_name} (Calorie/macros estimation coming soon)"
|
| 41 |
+
else:
|
| 42 |
+
feedback += "\nπ½οΈ No food data provided."
|
| 43 |
+
return feedback
|
| 44 |
+
|
| 45 |
+
diet_sleep = gr.Interface(
|
| 46 |
+
fn=diet_sleep_tracker,
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Slider(label="Sleep Hours", minimum=4, maximum=10, step=0.5),
|
| 49 |
+
gr.Image(type="filepath", label="Upload Food Photo (optional)"),
|
| 50 |
+
gr.Textbox(label="Or Type Food Name (e.g. '2 eggs and toast')")
|
| 51 |
+
],
|
| 52 |
+
outputs=gr.Textbox(label="Nutrition & Sleep Feedback"),
|
| 53 |
+
title="π½οΈ Nutrition + π€ Sleep Tracker"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# PAGE 3: Swim Technique Analyzer (placeholder)
|
| 57 |
+
def analyze_swim(video, stroke_type):
|
| 58 |
+
return f"Received video for stroke: {stroke_type}. AI analysis coming soon."
|
| 59 |
+
|
| 60 |
+
technique_analyzer = gr.Interface(
|
| 61 |
+
fn=analyze_swim,
|
| 62 |
+
inputs=[
|
| 63 |
+
gr.Video(label="Upload Swim Video"),
|
| 64 |
+
gr.Dropdown(["freestyle", "backstroke", "breaststroke", "butterfly"], label="Stroke Type")
|
| 65 |
+
],
|
| 66 |
+
outputs="text",
|
| 67 |
+
title="π AI Swim Technique Analyzer"
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
# PAGE 4: Profile
|
| 71 |
+
profile_data = {}
|
| 72 |
+
|
| 73 |
+
def save_profile(name, age, gender, goal, diet_type, pb100free):
|
| 74 |
+
profile_data["name"] = name
|
| 75 |
+
profile_data["age"] = age
|
| 76 |
+
profile_data["gender"] = gender
|
| 77 |
+
profile_data["goal"] = goal
|
| 78 |
+
profile_data["diet"] = diet_type
|
| 79 |
+
profile_data["pb100free"] = pb100free
|
| 80 |
+
return f"β
Profile saved for {name} (100 Free PB: {pb100free} sec)"
|
| 81 |
+
|
| 82 |
+
profile = gr.Interface(
|
| 83 |
+
fn=save_profile,
|
| 84 |
+
inputs=[
|
| 85 |
+
gr.Textbox(label="Name"),
|
| 86 |
+
gr.Number(label="Age"),
|
| 87 |
+
gr.Dropdown(["Male", "Female", "Other"], label="Gender"),
|
| 88 |
+
gr.Dropdown(["speed", "endurance", "technique", "recovery"], label="Main Goal"),
|
| 89 |
+
gr.Dropdown(["None", "Vegetarian", "Vegan", "High Protein"], label="Diet Type"),
|
| 90 |
+
gr.Number(label="100 Free Personal Best (sec)")
|
| 91 |
+
],
|
| 92 |
+
outputs="text",
|
| 93 |
+
title="π€ Swimmer Profile"
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# MULTI-PAGE APP
|
| 97 |
+
gr.TabbedInterface(
|
| 98 |
+
[daily_plan, diet_sleep, technique_analyzer, profile],
|
| 99 |
+
tab_names=["π
Daily Plan", "π΄ Nutrition & Sleep", "πΉ Technique", "π€ Profile"]
|
| 100 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|