srbhavya01 commited on
Commit
562c12e
·
verified ·
1 Parent(s): 65af30b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +71 -51
src/streamlit_app.py CHANGED
@@ -1,81 +1,101 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
- # -------------------------
5
- # 1. Function to Craft Prompt
6
- # -------------------------
7
 
8
- def create_workout_prompt(days, level, goal, equipment):
 
 
 
9
 
10
- prompt = f"""
11
- Generate a {days}-day workout plan.
12
 
13
- User Details:
14
- Fitness Level: {level}
15
- Goal: {goal}
16
- Available Equipment: {equipment}
 
 
 
 
17
 
18
- Requirements:
19
- - Include warm-up
20
- - Include exercises with sets and reps
21
- - Include rest time
22
- - Keep it structured day-wise
23
- """
24
 
25
- return prompt
26
 
 
 
27
 
28
  # -------------------------
29
- # 2. Load Model (Cached)
30
  # -------------------------
31
 
32
- @st.cache_resource
33
- def load_model():
34
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
35
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
36
- return tokenizer, model
 
37
 
38
- tokenizer, model = load_model()
 
 
 
39
 
 
 
 
 
40
 
41
  # -------------------------
42
- # Streamlit UI
43
  # -------------------------
44
 
45
- st.title("💪 FitPlan AI — Workout Generator")
46
-
47
- days = st.selectbox("Number of Days", [3, 4, 5, 6])
48
- level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
49
- goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength Gain"])
50
- equipment = st.text_input("Equipment (e.g., Dumbbells)")
 
 
 
 
 
 
 
 
51
 
52
  # -------------------------
53
- # Generate Button
54
  # -------------------------
55
 
56
- if st.button("Generate Workout Plan"):
57
 
58
- if not equipment:
59
- st.error("Please enter equipment")
 
 
 
 
 
60
  else:
61
- prompt = create_workout_prompt(days, level, goal, equipment)
 
 
 
 
62
 
63
- st.write("### Generated Prompt")
64
- st.code(prompt)
65
 
66
- with st.spinner("Generating plan..."):
67
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
68
 
69
- outputs = model.generate(
70
- **inputs,
71
- max_new_tokens=300,
72
- temperature=0.7,
73
- do_sample=True
74
- )
75
 
76
- result = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
77
 
78
- st.success("Workout Plan Generated ")
 
79
 
80
- st.subheader("🏋️ Your Workout Plan")
81
  st.write(result)
 
1
  import streamlit as st
2
+ from transformers import pipeline
 
 
 
 
3
 
4
+ # Load model only once
5
+ @st.cache_resource
6
+ def load_model():
7
+ return pipeline("text-generation", model="google/flan-t5-base")
8
 
9
+ generator = load_model()
 
10
 
11
+ st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="💪")
12
+ st.title("💪 FitPlan AI - Fitness Profile & BMI Calculator")
13
+
14
+ st.write("Fill in your details to calculate your BMI and get AI workout plan.")
15
+
16
+ # -------------------------
17
+ # 1. Personal Information
18
+ # -------------------------
19
 
20
+ name = st.text_input("Enter Your Name *")
 
 
 
 
 
21
 
22
+ gender = st.selectbox("Select Gender", ["Male", "Female", "Other"])
23
 
24
+ height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
25
+ weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
26
 
27
  # -------------------------
28
+ # 2. Fitness Details
29
  # -------------------------
30
 
31
+ st.subheader("Fitness Details")
32
+
33
+ goal = st.selectbox(
34
+ "Select Your Fitness Goal",
35
+ ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
36
+ )
37
 
38
+ equipment = st.multiselect(
39
+ "Available Equipment",
40
+ ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
41
+ )
42
 
43
+ fitness_level = st.radio(
44
+ "Fitness Level",
45
+ ["Beginner", "Intermediate", "Advanced"]
46
+ )
47
 
48
  # -------------------------
49
+ # BMI Functions
50
  # -------------------------
51
 
52
+ def calculate_bmi(weight, height_cm):
53
+ height_m = height_cm / 100
54
+ bmi = weight / (height_m ** 2)
55
+ return round(bmi, 2)
56
+
57
+ def bmi_category(bmi):
58
+ if bmi < 18.5:
59
+ return "Underweight"
60
+ elif bmi < 24.9:
61
+ return "Normal"
62
+ elif bmi < 29.9:
63
+ return "Overweight"
64
+ else:
65
+ return "Obese"
66
 
67
  # -------------------------
68
+ # Submit Button
69
  # -------------------------
70
 
71
+ if st.button("Submit Profile"):
72
 
73
+ # Validation
74
+ if not name:
75
+ st.error("Please enter your name.")
76
+ elif height_cm <= 0 or weight_kg <= 0:
77
+ st.error("Enter valid height and weight.")
78
+ elif not equipment:
79
+ st.error("Select at least one equipment option.")
80
  else:
81
+ st.success("✅ Profile Submitted Successfully!")
82
+
83
+ # Calculate BMI
84
+ bmi = calculate_bmi(weight_kg, height_cm)
85
+ bmi_status = bmi_category(bmi)
86
 
87
+ st.write(f"### 📊 BMI: {bmi} ({bmi_status})")
 
88
 
89
+ equipment_list = ", ".join(equipment)
 
90
 
91
+ prompt = f"""
92
+ Generate a 5-day structured workout plan.
 
 
 
 
93
 
94
+ Include warmup, exercises with sets & reps, rest time.
95
+ """
96
 
97
+ with st.spinner("Generating your AI workout plan..."):
98
+ result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
99
 
100
+ st.subheader("🏋️ Your Personalized Workout Plan")
101
  st.write(result)