Sreehitha-V commited on
Commit
176b1d7
·
verified ·
1 Parent(s): 1061124

Create src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +179 -0
src/streamlit_app.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
+
5
+ # 1. Page Configuration
6
+ st.set_page_config(page_title="PERSONALIZED FITPLAN", layout="centered")
7
+ def load_model():
8
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
9
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
10
+ return tokenizer, model
11
+
12
+ tokenizer, model = load_model()
13
+
14
+
15
+
16
+ def bmi_category(bmi):
17
+ if bmi < 18.5:
18
+ return "Underweight"
19
+ elif 18.5 <= bmi < 24.9:
20
+ return "Normal"
21
+ elif 25 <= bmi < 29.9:
22
+ return "Overweight"
23
+ else:
24
+ return "Obese"
25
+
26
+ # 2. Clean Styling
27
+ st.markdown("""
28
+ <style>
29
+ .stApp {
30
+ background: linear-gradient(rgba(0,0,0,0.85), rgba(0,0,0,0.85)),
31
+ url("https://images.unsplash.com/photo-1534438327276-14e5300c3a48?q=80&w=2070");
32
+ background-size: cover;
33
+ }
34
+ h1, h2, h3, label, p, span, .stMarkdown {
35
+ color: #FFFFFF !important;
36
+ font-weight: 900 !important;
37
+ }
38
+ </style>
39
+ """, unsafe_allow_html=True)
40
+
41
+ # 3. Header
42
+ st.title("🏋️ PERSONALIZED FITPLAN")
43
+ st.markdown("---")
44
+
45
+ # 4. Athlete Profile Form
46
+ st.header("Athlete Profile")
47
+ col1, col2 = st.columns(2)
48
+
49
+ with col1:
50
+ name = st.text_input("NAME (Required)")
51
+ gender = st.selectbox("GENDER", ["Male", "Female", "Other"])
52
+ height_cm = st.number_input("HEIGHT (CM) (Required)", min_value=0.0, step=0.1)
53
+
54
+ with col2:
55
+ weight_kg = st.number_input("WEIGHT (KG) (Required)", min_value=0.0, step=0.1)
56
+ goal = st.selectbox("FITNESS GOAL", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
57
+ level = st.selectbox("FITNESS LEVEL", ["Beginner", "Intermediate", "Advanced"])
58
+
59
+ equipment_options = [
60
+ "Dumbbells", "Barbell", "Kettlebells", "Weight Plates",
61
+ "Resistance Band", "Yoga Mat", "Pull-up Bar", "Bench Press", "No Equipment"
62
+ ]
63
+ equipment = st.multiselect("AVAILABLE EQUIPMENT", equipment_options)
64
+
65
+ st.markdown("---")
66
+
67
+ # 5. Logic and Results
68
+ if st.button(" Submit Profile"):
69
+
70
+ if not name:
71
+ st.error("Please enter your name.")
72
+
73
+ # 🔧 FIXED VARIABLES
74
+ elif height_cm <= 0 or weight_kg <= 0:
75
+ st.error("Please enter valid height and weight.")
76
+
77
+ elif not equipment:
78
+ st.error("Please select at least one equipment option.")
79
+
80
+ else:
81
+ st.success(" Profile Submitted Successfully!")
82
+
83
+ # 🔧 BMI CALCULATION (missing earlier)
84
+ height_m = height_cm / 100
85
+ bmi = weight_kg / (height_m ** 2)
86
+ bmi_status = bmi_category(bmi)
87
+
88
+ equipment_list = ", ".join(equipment)
89
+
90
+ prompt = f"""
91
+ You are a certified professional gym trainer.
92
+
93
+ Generate a COMPLETE 5-day workout schedule.
94
+
95
+ FORMAT:
96
+
97
+ Day 1:
98
+ Warm-up:
99
+ -
100
+ Workout:
101
+ -
102
+ Rest:
103
+
104
+ Day 2:
105
+ Warm-up:
106
+ -
107
+ Workout:
108
+ -
109
+ Rest:
110
+
111
+ Day 3:
112
+ Warm-up:
113
+ -
114
+ Workout:
115
+ -
116
+ Rest:
117
+
118
+ Day 4:
119
+ Warm-up:
120
+ -
121
+ Workout:
122
+ -
123
+ Rest:
124
+
125
+ Day 5:
126
+ Warm-up:
127
+ -
128
+ Workout:
129
+ -
130
+ Rest:
131
+
132
+ User Details:
133
+ Gender: {gender}
134
+ BMI: {bmi:.2f} ({bmi_status})
135
+ Goal: {goal}
136
+ Fitness Level: {level}
137
+ Available Equipment: {equipment_list}
138
+
139
+ Generate the full 5-day workout plan.
140
+ """
141
+
142
+ with st.spinner("Generating your AI workout plan..."):
143
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
144
+ outputs = model.generate(
145
+ **inputs,
146
+ max_new_tokens=600,
147
+ temperature=0.3,
148
+ do_sample=False
149
+ )
150
+
151
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
152
+
153
+ st.subheader(" Your Personalized Workout Plan")
154
+ st.write(result)
155
+
156
+ # Validation block (unchanged)
157
+ if not name or height_cm <= 0 or weight_kg <= 0:
158
+ st.error("🚨 VALIDATION FAILED: PLEASE PROVIDE NAME, HEIGHT, AND WEIGHT.")
159
+ else:
160
+ height_m = height_cm / 100
161
+ bmi_val = round(weight_kg / (height_m ** 2), 2)
162
+
163
+ if bmi_val < 18.5: category = "Underweight"
164
+ elif 18.5 <= bmi_val < 24.9: category = "Normal"
165
+ elif 25 <= bmi_val < 29.9: category = "Overweight"
166
+ else: category = "Obese"
167
+
168
+ st.success(f"PROFILE SUBMITTED SUCCESSFULLY! HELLO {name.upper()}")
169
+ st.markdown(f"### BMI: {bmi_val} | CATEGORY: {category.upper()}")
170
+
171
+ athlete_data = {
172
+ "Name": name,
173
+ "Gender": gender,
174
+ "BMI": bmi_val,
175
+ "Goal": goal,
176
+ "Fitness Level": level,
177
+ "Equipment": equipment
178
+ }
179
+ st.json(athlete_data)