srustik123 commited on
Commit
51e2b69
·
verified ·
1 Parent(s): 0256831

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +59 -39
src/streamlit_app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
3
  # -------------------------
4
  # PAGE CONFIG
5
  # -------------------------
@@ -69,54 +70,73 @@ with st.form("fitness_form"):
69
  # -------------------------
70
  # HANDLE SUBMISSION
71
  # -------------------------
72
- if submit:
73
 
74
- if not name.strip():
75
- st.error("Please enter your name.")
 
76
 
 
 
77
  elif height <= 0 or weight <= 0:
78
- st.error("Height and Weight must be positive values.")
79
 
 
 
80
  elif not equipment:
81
- st.error("Please select at least one equipment option.")
82
 
 
 
83
  else:
84
- # Calculate BMI
85
- user_bmi = calculate_bmi(weight, height)
86
- bmi_status = get_category(user_bmi)
87
 
88
- st.success(f" Profile Created Successfully for {name}!")
89
- st.metric("Your BMI", user_bmi)
90
- st.info(f"Health Category: **{bmi_status}**")
91
 
92
  equipment_list = ", ".join(equipment)
93
-
94
- # FLAN-T5 works best with instruction-style prompts
95
  prompt = f"""
96
- Create a structured 5-day workout plan.
97
-
98
- User Details:
99
- Name: {name}
100
- BMI: {user_bmi} ({bmi_status})
101
- Goal: {goal}
102
- Fitness Level: {level}
103
- Equipment: {equipment_list}
104
-
105
- Include:
106
- - Warm-up
107
- - Exercises with sets and reps
108
- - Rest time
109
- - Day-wise breakdown
110
- - Safety advice
111
- """
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  with st.spinner("Generating your AI workout plan..."):
114
- result = generator(
115
- prompt,
116
- max_new_tokens=400,
117
- do_sample=True,
118
- temperature=0.7
119
- )[0]["generated_text"]
120
-
121
- st.subheader("🏋️ Your Personalized Workout Plan")
122
- st.write(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
  # -------------------------
5
  # PAGE CONFIG
6
  # -------------------------
 
70
  # -------------------------
71
  # HANDLE SUBMISSION
72
  # -------------------------
73
+ # SUBMIT BUTTON
74
 
75
+ if st.button(" Submit Profile"):
76
+
77
+ if not name:
78
 
79
+ st.error("Please enter your name.")
80
+
81
  elif height <= 0 or weight <= 0:
 
82
 
83
+ st.error("Please enter valid height and weight.")
84
+
85
  elif not equipment:
 
86
 
87
+ st.error("Please select at least one equipment option.")
88
+
89
  else:
 
 
 
90
 
91
+ st.success(" Profile Submitted Successfully!")
92
+
93
+ bmi_status = bmi_category(bmi)
94
 
95
  equipment_list = ", ".join(equipment)
96
+
 
97
  prompt = f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
+ You are a certified professional fitness trainer.
100
+
101
+ Create a detailed 5-day workout plan.
102
+
103
+ User Information:
104
+
105
+ - Gender: {gender}
106
+
107
+ - BMI: {bmi:.2f} ({bmi_status})
108
+
109
+ - Goal: {goal}
110
+
111
+ - Fitness Level: {fitness_level}
112
+
113
+ - Equipment Available: {equipment_list}
114
+
115
+ Start directly with:
116
+
117
+ Day 1:
118
+
119
+ """
120
+
121
  with st.spinner("Generating your AI workout plan..."):
122
+
123
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
124
+
125
+ outputs = model.generate(
126
+
127
+ **inputs,
128
+
129
+ max_new_tokens=900,
130
+
131
+ temperature=0.7,
132
+
133
+ do_sample=True
134
+
135
+ )
136
+
137
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
138
+
139
+ st.subheader(" Your Personalized Workout Plan")
140
+
141
+ st.write(result)
142
+