srustik123 commited on
Commit
e7fb064
·
verified ·
1 Parent(s): 9d4fd7f

Delete src

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +0 -152
src/streamlit_app.py DELETED
@@ -1,152 +0,0 @@
1
- import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
-
5
- # -------------------------
6
- # PAGE CONFIG
7
- # -------------------------
8
- st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
9
-
10
- st.title("💪 FitPlan-AI: Personalized Fitness Profile")
11
-
12
- # -------------------------
13
- # BMI FUNCTIONS
14
- # -------------------------
15
- def calculate_bmi(weight, height_cm):
16
- height_m = height_cm / 100
17
- return round(weight / (height_m ** 2), 2)
18
-
19
- def get_category(bmi):
20
- if bmi < 18.5:
21
- return "Underweight"
22
- elif bmi < 24.9:
23
- return "Normal"
24
- elif bmi < 29.9:
25
- return "Overweight"
26
- else:
27
- return "Obese"
28
-
29
- # -------------------------
30
- # LOAD MODEL
31
- # -------------------------
32
- @st.cache_resource
33
- def load_model():
34
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
35
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
36
- return tokenizer, model
37
-
38
- tokenizer, model = load_model()
39
-
40
- # -------------------------
41
- # FORM
42
- # -------------------------
43
- with st.form("fitness_form"):
44
-
45
- st.subheader("Personal Information")
46
-
47
- name = st.text_input("Full Name*", placeholder="Enter your name")
48
-
49
- col1, col2 = st.columns(2)
50
- with col1:
51
- height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
52
- with col2:
53
- weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
54
-
55
- st.subheader("Fitness Details")
56
-
57
- goal = st.selectbox(
58
- "Fitness Goal",
59
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
60
- )
61
-
62
- level = st.radio(
63
- "Fitness Level",
64
- ["Beginner", "Intermediate", "Advanced"]
65
- )
66
-
67
- equipment = st.multiselect(
68
- "Available Equipment",
69
- ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment",
70
- "Kettlebell", "Pull-up Bar"]
71
- )
72
-
73
- submit = st.form_submit_button("Submit Profile")
74
-
75
- # -------------------------
76
- # HANDLE SUBMISSION
77
- # -------------------------
78
- if submit:
79
-
80
- if not name:
81
- st.error("Please enter your name.")
82
-
83
- elif height <= 0 or weight <= 0:
84
- st.error("Please enter valid height and weight.")
85
-
86
- elif not equipment:
87
- st.error("Please select at least one equipment option.")
88
-
89
- else:
90
- st.success("Profile Submitted Successfully!")
91
-
92
- # Calculate BMI
93
- bmi = calculate_bmi(weight, height)
94
- bmi_status = get_category(bmi)
95
-
96
- st.write(f"### 📊 Your BMI: {bmi} ({bmi_status})")
97
-
98
- equipment_list = ", ".join(equipment)
99
-
100
- # -------------------------
101
- # GENERATE 5-DAY PLAN (LOOP METHOD)
102
- # -------------------------
103
- with st.spinner("Generating your 5-day workout plan..."):
104
-
105
- full_plan = ""
106
-
107
- for day in range(1, 6):
108
-
109
- prompt = f"""
110
- You are a certified professional fitness trainer.
111
-
112
- Create a detailed workout plan for Day {day}.
113
-
114
- Include:
115
- - Warm-up
116
- - 4 to 6 exercises
117
- - Sets and reps
118
- - Cool down
119
-
120
- User Details:
121
- BMI: {bmi} ({bmi_status})
122
- Goal: {goal}
123
- Fitness Level: {level}
124
- Equipment Available: {equipment_list}
125
-
126
- Start with:
127
-
128
- Day {day}:
129
- """
130
-
131
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
132
-
133
- outputs = model.generate(
134
- **inputs,
135
- max_new_tokens=350,
136
- temperature=0.8,
137
- do_sample=True,
138
- repetition_penalty=1.1
139
- )
140
-
141
- result = tokenizer.decode(
142
- outputs[0],
143
- skip_special_tokens=True
144
- ).strip()
145
-
146
- full_plan += result + "\n\n"
147
-
148
- # -------------------------
149
- # DISPLAY PLAN
150
- # -------------------------
151
- st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
152
- st.write(full_plan)