srbhavya01 commited on
Commit
66f098b
·
verified ·
1 Parent(s): ee2f981

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +57 -46
src/streamlit_app.py CHANGED
@@ -2,48 +2,65 @@ import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  import torch
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @st.cache_resource
6
  def load_model():
7
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
8
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large
9
  return tokenizer, model
10
 
11
- # ⭐ MUST CALL FUNCTION
12
  tokenizer, model = load_model()
13
 
 
 
 
14
 
15
- # Page Config
16
-
17
- st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="💪")
18
- st.title("💪 FitPlan AI - Fitness Profile & BMI Calculator")
19
-
20
- st.write("Fill in your details to calculate your BMI and get AI workout plan.")
21
 
22
  # -------------------------
23
- # 1. Personal Information
24
  # -------------------------
25
 
26
  name = st.text_input("Enter Your Name *")
27
-
28
- gender = st.selectbox("Select Gender", ["Male", "Female", "Other"])
29
-
30
- height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
31
- weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
32
 
33
  # -------------------------
34
- # 2. Fitness Details
35
  # -------------------------
36
 
37
- st.subheader("Fitness Details")
38
-
39
  goal = st.selectbox(
40
- "Select Your Fitness Goal",
41
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
42
  )
43
 
44
  equipment = st.multiselect(
45
  "Available Equipment",
46
- ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope", "Weight plates", "Cycling", "Inclined bench","Pullups Bar", "No Equipment"]
 
47
  )
48
 
49
  fitness_level = st.radio(
@@ -55,10 +72,9 @@ fitness_level = st.radio(
55
  # BMI Functions
56
  # -------------------------
57
 
58
- def calculate_bmi(weight, height_cm):
59
- height_m = height_cm / 100
60
- bmi = weight / (height_m ** 2)
61
- return round(bmi, 2)
62
 
63
  def bmi_category(bmi):
64
  if bmi < 18.5:
@@ -71,52 +87,47 @@ def bmi_category(bmi):
71
  return "Obese"
72
 
73
  # -------------------------
74
- # Submit Button
75
  # -------------------------
76
 
77
- if st.button("Submit Profile"):
78
 
79
- # Validation
80
  if not name:
81
- st.error("Please enter your name.")
82
  elif height_cm <= 0 or weight_kg <= 0:
83
- st.error("Enter valid height and weight.")
84
  elif not equipment:
85
- st.error("Select at least one equipment option.")
86
  else:
87
- st.success("✅ Profile Submitted Successfully!")
88
-
89
- # Calculate BMI
90
  bmi = calculate_bmi(weight_kg, height_cm)
91
  bmi_status = bmi_category(bmi)
92
 
93
- st.write(f"### 📊 BMI: {bmi} ({bmi_status})")
94
 
95
  equipment_list = ", ".join(equipment)
96
 
97
  prompt = f"""
98
- Generate a 5-day structured workout plan.
99
 
100
- User Details:
101
  Name: {name}
102
  Gender: {gender}
103
  BMI: {bmi} ({bmi_status})
104
  Goal: {goal}
105
- Fitness Level: {fitness_level}
106
- Available Equipment: {equipment_list}
107
 
108
- Include warmup, exercises with sets & reps, rest time.
109
  """
110
 
111
- with st.spinner("Generating your AI workout plan..."):
112
- inputs = tokenizer(prompt, return_tensors="pt", truncation= True)
113
  outputs = model.generate(
114
  **inputs,
115
- max_new_tokens=600,
116
- temperature= 0.7,
117
- do_sample= True
118
  )
119
- result = tokenizer.decode(outputs[0], skip_special_tokens= True)
120
 
121
- st.subheader("🏋️ Your Personalized Workout Plan")
122
  st.write(result)
 
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  import torch
4
 
5
+ # -------------------------
6
+ # Page Config FIRST
7
+ # -------------------------
8
+
9
+ st.set_page_config(page_title="FitPlan AI", page_icon="💪")
10
+
11
+ # 🎨 Background Style
12
+ st.markdown(
13
+ """
14
+ <style>
15
+ .stApp {
16
+ background: linear-gradient(to right, #ff512f, #dd2476);
17
+ }
18
+ </style>
19
+ """,
20
+ unsafe_allow_html=True
21
+ )
22
+
23
+ # -------------------------
24
+ # Load Model (Small for HF)
25
+ # -------------------------
26
+
27
  @st.cache_resource
28
  def load_model():
29
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
30
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
31
  return tokenizer, model
32
 
 
33
  tokenizer, model = load_model()
34
 
35
+ # -------------------------
36
+ # App Title
37
+ # -------------------------
38
 
39
+ st.title("💪 FitPlan AI - BMI Calculator & Workout Planner")
40
+ st.write("Enter your details to get AI workout plan.")
 
 
 
 
41
 
42
  # -------------------------
43
+ # Personal Info
44
  # -------------------------
45
 
46
  name = st.text_input("Enter Your Name *")
47
+ gender = st.selectbox("Gender", ["Male", "Female", "Other"])
48
+ height_cm = st.number_input("Height (cm)", min_value=0.0)
49
+ weight_kg = st.number_input("Weight (kg)", min_value=0.0)
 
 
50
 
51
  # -------------------------
52
+ # Fitness Details
53
  # -------------------------
54
 
 
 
55
  goal = st.selectbox(
56
+ "Fitness Goal",
57
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
58
  )
59
 
60
  equipment = st.multiselect(
61
  "Available Equipment",
62
+ ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
63
+ "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
64
  )
65
 
66
  fitness_level = st.radio(
 
72
  # BMI Functions
73
  # -------------------------
74
 
75
+ def calculate_bmi(weight, height):
76
+ height_m = height / 100
77
+ return round(weight / (height_m ** 2), 2)
 
78
 
79
  def bmi_category(bmi):
80
  if bmi < 18.5:
 
87
  return "Obese"
88
 
89
  # -------------------------
90
+ # Generate Plan
91
  # -------------------------
92
 
93
+ if st.button("Generate Workout Plan"):
94
 
 
95
  if not name:
96
+ st.error("Enter your name")
97
  elif height_cm <= 0 or weight_kg <= 0:
98
+ st.error("Enter valid height & weight")
99
  elif not equipment:
100
+ st.error("Select equipment")
101
  else:
 
 
 
102
  bmi = calculate_bmi(weight_kg, height_cm)
103
  bmi_status = bmi_category(bmi)
104
 
105
+ st.success(f"BMI: {bmi} ({bmi_status})")
106
 
107
  equipment_list = ", ".join(equipment)
108
 
109
  prompt = f"""
110
+ Create a 5-day workout plan.
111
 
 
112
  Name: {name}
113
  Gender: {gender}
114
  BMI: {bmi} ({bmi_status})
115
  Goal: {goal}
116
+ Level: {fitness_level}
117
+ Equipment: {equipment_list}
118
 
119
+ Include warmup, exercises, sets, reps, rest time.
120
  """
121
 
122
+ with st.spinner("Generating workout plan..."):
123
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
124
  outputs = model.generate(
125
  **inputs,
126
+ max_new_tokens=400,
127
+ temperature=0.7,
128
+ do_sample=True
129
  )
130
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
131
 
132
+ st.subheader("🏋️ Your Workout Plan")
133
  st.write(result)