Harry2406 commited on
Commit
9fde360
·
verified ·
1 Parent(s): 9d85220

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +48 -89
src/streamlit_app.py CHANGED
@@ -1,90 +1,49 @@
1
- import streamlit as st
2
-
3
- st.set_page_config(page_title="Fitness Profile", page_icon="🏋️", layout="centered")
4
-
5
- st.title("🏋️ Personalized Fitness Profile")
6
-
7
- st.markdown("---")
8
-
9
- # =========================
10
- # 1️⃣ Personal Information
11
- # =========================
12
- st.header("1. Personal Information")
13
-
14
- name = st.text_input("Name *")
15
-
16
- height_cm = st.number_input("Height (in centimeters) *", min_value=0.0, format="%.2f")
17
- weight_kg = st.number_input("Weight (in kilograms) *", min_value=0.0, format="%.2f")
18
-
19
- # =========================
20
- # 2️⃣ Fitness Details
21
- # =========================
22
- st.header("2. Fitness Details")
23
-
24
- fitness_goal = st.selectbox(
25
- "Fitness Goal",
26
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
27
- )
28
-
29
- equipment = st.multiselect(
30
- "Available Equipment (Multiple selection allowed)",
31
- ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
32
- )
33
-
34
- fitness_level = st.radio(
35
- "Fitness Level",
36
- ["Beginner", "Intermediate", "Advanced"],
37
- horizontal=True
38
- )
39
-
40
- st.markdown("---")
41
-
42
- # =========================
43
- # 3️⃣ Submit Button
44
- # =========================
45
- if st.button("Generate Profile"):
46
-
47
- # =========================
48
- # Validation
49
- # =========================
50
- if name.strip() == "":
51
- st.error("❌ Name is required.")
52
- elif height_cm <= 0:
53
- st.error("❌ Height must be greater than zero.")
54
- elif weight_kg <= 0:
55
- st.error("❌ Weight must be greater than zero.")
56
  else:
57
- # =========================
58
- # BMI Calculation
59
- # =========================
60
- height_m = height_cm / 100 # Convert cm to meters
61
- bmi = weight_kg / (height_m ** 2)
62
- bmi = round(bmi, 2)
63
-
64
- # =========================
65
- # BMI Category
66
- # =========================
67
- if bmi < 18.5:
68
- category = "Underweight"
69
- elif 18.5 <= bmi < 24.9:
70
- category = "Normal"
71
- elif 25 <= bmi < 29.9:
72
- category = "Overweight"
73
- else:
74
- category = "Obese"
75
-
76
- # =========================
77
- # Display Results
78
- # =========================
79
- st.success("✅ Profile Generated Successfully!")
80
-
81
- st.subheader(f"👤 {name}'s Fitness Summary")
82
-
83
- st.write(f"**Height (m):** {round(height_m, 2)} m")
84
- st.write(f"**Weight (kg):** {weight_kg} kg")
85
- st.write(f"**BMI:** {bmi}")
86
- st.write(f"**BMI Category:** {category}")
87
- st.write(f"**Fitness Goal:** {fitness_goal}")
88
- st.write(f"**Fitness Level:** {fitness_level}")
89
- st.write(f"**Available Equipment:** {', '.join(equipment) if equipment else 'None Selected'}")
90
-
 
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)