Harry2406 commited on
Commit
b0b037e
·
verified ·
1 Parent(s): 1d7bb64

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +87 -46
src/streamlit_app.py CHANGED
@@ -1,48 +1,89 @@
1
- import streamlit st
2
  from transformers import pipeline
3
- def load_model():
4
- return pipeline(
5
- "text-generation",
6
- model="google/flan-t5-base"
7
- )
8
-
9
- generator = load_model()
10
- if not name:
11
- st.error("Please enter your name.")
12
-
13
- elif not equipment:
14
- st.error("Please select at least one equipment option.")
15
-
16
- elif bmi is None:
17
- st.error("Please enter valid height and weight.")
18
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  else:
20
- st.success("✅ Profile Submitted Successfully!")
21
-
22
- bmi_status = bmi_category(bmi)
23
- equipment_list = ", ".join(equipment)
24
-
25
- prompt = f"""
26
- Generate a 5-day structured workout plan.
27
-
28
- User Details:
29
- Name: {name}
30
- Gender: {gender}
31
- BMI: {bmi:.2f} ({bmi_status})
32
- Goal: {goal}
33
- Fitness Level: {fitness_level}
34
- Available Equipment: {equipment_list}
35
-
36
- Requirements:
37
- - Include warmup
38
- - Include exercises with sets and reps
39
- - Include rest time
40
- - Adjust intensity based on BMI and fitness level
41
- - Keep it structured day-wise
42
- """
43
-
44
- with st.spinner("Generating your AI workout plan..."):
45
- result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
46
-
47
- st.subheader("🏋️ Your Personalized Workout Plan")
48
- st.write(result)
 
 
 
 
 
1
+ import streamlit as st
2
  from transformers import pipeline
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'}")