srbhavya01 commited on
Commit
8f32f3f
ยท
verified ยท
1 Parent(s): 7c9ec2f

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +49 -80
src/streamlit_app.py CHANGED
@@ -1,81 +1,50 @@
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",
26
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
27
- )
28
-
29
- equipment = st.multiselect(
30
- "Available Equipment (Select multiple if available)",
31
- ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
32
- )
33
-
34
- fitness_level = st.radio(
35
- "Select Your Fitness Level",
36
- ["Beginner", "Intermediate", "Advanced"]
37
- )
38
-
39
- # -------------------------
40
- # BMI Calculation Function
41
- # -------------------------
42
-
43
- def calculate_bmi(weight, height_cm):
44
- height_m = height_cm / 100 # Convert cm to meters
45
- bmi = weight / (height_m ** 2)
46
- return round(bmi, 2)
47
-
48
- def bmi_category(bmi):
49
- if bmi < 18.5:
50
- return "Underweight"
51
- elif 18.5 <= bmi < 24.9:
52
- return "Normal"
53
- elif 25 <= bmi < 29.9:
54
- return "Overweight"
55
  else:
56
- return "Obese"
57
-
58
- # -------------------------
59
- # Submit Button
60
- # -------------------------
61
-
62
- if st.button("Calculate BMI"):
63
-
64
- # Validation
65
- if not name or height_cm <= 0 or weight_kg <= 0:
66
- st.error("โš  Please fill all required fields with valid values!")
67
- else:
68
- bmi = calculate_bmi(weight_kg, height_cm)
69
- category = bmi_category(bmi)
70
-
71
- st.success("โœ… Calculation Successful!")
72
-
73
- st.write(f"### ๐Ÿ‘ค Name: {name}")
74
- st.write(f"### ๐Ÿ“Š Your BMI: {bmi}")
75
- st.write(f"### ๐Ÿท BMI Category: {category}")
76
-
77
- st.write("---")
78
- st.write("### ๐Ÿ‹ Fitness Summary")
79
- st.write(f"**Goal:** {goal}")
80
- st.write(f"**Fitness Level:** {fitness_level}")
81
- st.write(f"**Equipment Available:** {', '.join(equipment) if equipment else 'None selected'}")
 
 
 
 
 
1
+ def load_model():
2
+ return pipeline(
3
+ "text-generation",
4
+ model="google/flan-t5-base"
5
+ )
6
+
7
+ generator = load_model()
8
+ from transformers import pipeline
9
+ if st.button("Submit Profile"):
10
+
11
+ if not name:
12
+ st.error("Please enter your name.")
13
+
14
+ elif not equipment:
15
+ st.error("Please select at least one equipment option.")
16
+
17
+ elif bmi is None:
18
+ st.error("Please enter valid height and weight.")
19
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  else:
21
+ st.success("โœ… Profile Submitted Successfully!")
22
+
23
+ bmi_status = bmi_category(bmi)
24
+ equipment_list = ", ".join(equipment)
25
+
26
+ prompt = f"""
27
+ Generate a 5-day structured workout plan.
28
+
29
+ User Details:
30
+ Name: {name}
31
+ Gender: {gender}
32
+ BMI: {bmi:.2f} ({bmi_status})
33
+ Goal: {goal}
34
+ Fitness Level: {fitness_level}
35
+ Available Equipment: {equipment_list}
36
+
37
+ Requirements:
38
+ - Include warmup
39
+ - Include exercises with sets and reps
40
+ - Include rest time
41
+ - Adjust intensity based on BMI and fitness level
42
+ - Keep it structured day-wise
43
+ """
44
+
45
+ with st.spinner("Generating your AI workout plan..."):
46
+ result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
47
+
48
+ st.subheader("๐Ÿ‹๏ธ Your Personalized Workout Plan")
49
+ st.write(result)
50
+