styx102 commited on
Commit
a6d3661
Β·
verified Β·
1 Parent(s): 2df24ec

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +100 -0
  2. 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