js02vel commited on
Commit
ea6a5be
·
verified ·
1 Parent(s): 30f73f0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +16 -16
src/streamlit_app.py CHANGED
@@ -1,38 +1,38 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Load model
5
  @st.cache_resource
6
  def load_model():
7
  return pipeline(
8
  "text2text-generation",
9
- model="google/flan-t5-base"
10
  )
11
 
12
- model = load_model()
13
 
14
  st.set_page_config(page_title="Fitness Plan AI", layout="centered")
15
 
16
  st.title("🏋️ Fitness Plan AI Generator")
17
  st.write("Generate a personalized fitness plan using AI")
18
 
19
- # User inputs
20
- age = st.number_input("Age", 15, 80, 22)
21
  gender = st.selectbox("Gender", ["Male", "Female"])
22
  goal = st.selectbox("Fitness Goal", ["Weight Loss", "Muscle Gain", "General Fitness"])
23
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
24
  days = st.slider("Workout Days per Week", 1, 7, 4)
25
 
26
  if st.button("Generate Fitness Plan"):
27
- prompt = f"""
28
- Create a {days}-day fitness plan for a {age}-year-old {gender}.
29
- Goal: {goal}
30
- Level: {level}
31
- Include warm-up, main workout, and cool-down.
32
- """
33
-
34
- with st.spinner("Generating plan..."):
35
- output = model(prompt, max_length=300)
36
- st.success("Your Fitness Plan:")
37
- st.write(output[0]['generated_text'])
38
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Cache model to avoid reloading
5
  @st.cache_resource
6
  def load_model():
7
  return pipeline(
8
  "text2text-generation",
9
+ model="google/flan-t5-small" # smaller & safer for HF Spaces
10
  )
11
 
12
+ generator = load_model()
13
 
14
  st.set_page_config(page_title="Fitness Plan AI", layout="centered")
15
 
16
  st.title("🏋️ Fitness Plan AI Generator")
17
  st.write("Generate a personalized fitness plan using AI")
18
 
19
+ # User Inputs
20
+ age = st.number_input("Age", min_value=15, max_value=80, value=22)
21
  gender = st.selectbox("Gender", ["Male", "Female"])
22
  goal = st.selectbox("Fitness Goal", ["Weight Loss", "Muscle Gain", "General Fitness"])
23
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
24
  days = st.slider("Workout Days per Week", 1, 7, 4)
25
 
26
  if st.button("Generate Fitness Plan"):
27
+ prompt = (
28
+ f"Create a {days}-day fitness workout plan for a "
29
+ f"{age}-year-old {gender}. "
30
+ f"Goal: {goal}. "
31
+ f"Fitness level: {level}. "
32
+ f"Include warm-up, main workout, and cool-down."
33
+ )
 
 
 
 
34
 
35
+ with st.spinner("Generating your fitness plan..."):
36
+ result = generator(prompt, max_length=300, do_sample=True)
37
+ st.success("✅ Your Fitness Plan")
38
+ st.write(result[0]["generated_text"])