srbhavya01 commited on
Commit
2030b3f
Β·
verified Β·
1 Parent(s): c72e92d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +43 -85
src/streamlit_app.py CHANGED
@@ -1,36 +1,25 @@
1
  import streamlit as st
2
- import torch
3
- import random
4
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
 
 
6
 
7
- # -------------------------
8
- # Page Config
9
- # -------------------------
10
-
11
- st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ")
12
 
13
- st.title("πŸ’ͺ FitPlan AI β€” Personalized Workout Generator")
14
-
15
- st.write("Fill your details to generate AI workout plan.")
16
 
17
  # -------------------------
18
- # Load Model (Small for HF Spaces)
19
  # -------------------------
20
 
21
- @st.cache_resource
22
- def load_model():
23
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
24
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
25
- return tokenizer, model
26
 
27
- tokenizer, model = load_model()
 
28
 
29
  # -------------------------
30
- # User Inputs
31
  # -------------------------
32
 
33
- name = st.text_input("Enter Your Name")
34
 
35
  goal = st.selectbox(
36
  "Select Your Fitness Goal",
@@ -38,87 +27,56 @@ goal = st.selectbox(
38
  )
39
 
40
  equipment = st.multiselect(
41
- "Available Equipment",
42
  ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
43
  "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
44
  )
45
 
46
  fitness_level = st.radio(
47
- "Fitness Level",
48
  ["Beginner", "Intermediate", "Advanced"]
49
  )
50
 
51
  # -------------------------
52
- # Function: Create Prompt
53
  # -------------------------
54
 
55
- def create_prompt(goal, equipment, fitness_level):
56
-
57
- equipment_list = ", ".join(equipment)
58
-
59
- # Goal instructions
60
- goal_map = {
61
- "Build Muscle": "Focus on muscle hypertrophy training.",
62
- "Weight Loss": "Focus on fat burning and cardio workouts.",
63
- "Strength Gain": "Focus on heavy compound strength exercises.",
64
- "Abs Building": "Focus on core and abdominal exercises.",
65
- "Flexible": "Focus on stretching and mobility exercises."
66
- }
67
-
68
- # Level instructions
69
- level_map = {
70
- "Beginner": "Use simple low intensity exercises.",
71
- "Intermediate": "Use moderate intensity exercises.",
72
- "Advanced": "Use high intensity advanced exercises."
73
- }
74
-
75
- prompt = f"""
76
- Generate a 5-day workout plan.
77
-
78
- Goal: {goal}
79
- Fitness Level: {fitness_level}
80
- Equipment: {equipment_list}
81
-
82
- Goal Instruction:
83
- {goal_map[goal]}
84
-
85
- Level Instruction:
86
- {level_map[fitness_level]}
87
-
88
- Requirements:
89
- - Include warm-up
90
- - Exercises with sets and reps
91
- - Rest time
92
- - Day-wise structure
93
- """
94
-
95
- return prompt
96
 
97
  # -------------------------
98
- # Generate Plan
99
  # -------------------------
100
 
101
- if st.button("Generate Workout Plan"):
102
-
103
- if not name:
104
- st.error("Enter your name")
105
- elif not equipment:
106
- st.error("Select at least one equipment")
107
  else:
108
- prompt = create_prompt(goal, equipment, fitness_level)
109
-
110
- with st.spinner("Generating your AI workout plan..."):
111
-
112
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
113
 
114
- outputs = model.generate(
115
- **inputs,
116
- max_new_tokens=400,
117
- temperature=0.9,
118
- do_sample=True
119
- )
120
 
121
- result = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
122
 
123
- st.success(f"Workout Plan for {name}")
124
- st.write(result)
 
 
 
 
1
  import streamlit as st
 
 
 
2
 
3
+ st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="πŸ’ͺ")
4
 
5
+ st.title("πŸ’ͺ FitPlan AI - Fitness Profile & BMI Calculator")
 
 
 
 
6
 
7
+ st.write("Fill in your details to calculate your BMI and fitness category.")
 
 
8
 
9
  # -------------------------
10
+ # 1. Personal Information
11
  # -------------------------
12
 
13
+ name = st.text_input("Enter Your Name *")
 
 
 
 
14
 
15
+ height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
16
+ weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
17
 
18
  # -------------------------
19
+ # 2. Fitness Details
20
  # -------------------------
21
 
22
+ st.subheader("Fitness Details")
23
 
24
  goal = st.selectbox(
25
  "Select Your Fitness Goal",
 
27
  )
28
 
29
  equipment = st.multiselect(
30
+ "Available Equipment (Select multiple if available)",
31
  ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
32
  "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
33
  )
34
 
35
  fitness_level = st.radio(
36
+ "Select Your Fitness Level",
37
  ["Beginner", "Intermediate", "Advanced"]
38
  )
39
 
40
  # -------------------------
41
+ # BMI Calculation Function
42
  # -------------------------
43
 
44
+ def calculate_bmi(weight, height_cm):
45
+ height_m = height_cm / 100 # Convert cm to meters
46
+ bmi = weight / (height_m ** 2)
47
+ return round(bmi, 2)
48
+
49
+ def bmi_category(bmi):
50
+ if bmi < 18.5:
51
+ return "Underweight"
52
+ elif 18.5 <= bmi < 24.9:
53
+ return "Normal"
54
+ elif 25 <= bmi < 29.9:
55
+ return "Overweight"
56
+ else:
57
+ return "Obese"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  # -------------------------
60
+ # Submit Button
61
  # -------------------------
62
 
63
+ if st.button("Calculate BMI"):
64
+
65
+ # Validation
66
+ if not name or height_cm <= 0 or weight_kg <= 0:
67
+ st.error("⚠ Please fill all required fields with valid values!")
 
68
  else:
69
+ bmi = calculate_bmi(weight_kg, height_cm)
70
+ category = bmi_category(bmi)
 
 
 
71
 
72
+ st.success("βœ… Calculation Successful!")
 
 
 
 
 
73
 
74
+ st.write(f"### πŸ‘€ Name: {name}")
75
+ st.write(f"### πŸ“Š Your BMI: {bmi}")
76
+ st.write(f"### 🏷 BMI Category: {category}")
77
 
78
+ st.write("---")
79
+ st.write("### πŸ‹ Fitness Summary")
80
+ st.write(f"**Goal:** {goal}")
81
+ st.write(f"**Fitness Level:** {fitness_level}")
82
+ st.write(f"**Equipment Available:** {', '.join(equipment) if equipment else 'None selected'}")