js02vel commited on
Commit
34dd986
·
verified ·
1 Parent(s): ea6a5be

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +13 -15
src/streamlit_app.py CHANGED
@@ -1,28 +1,26 @@
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 "
@@ -32,7 +30,7 @@ if st.button("Generate Fitness Plan"):
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"])
 
1
  import streamlit as st
2
+ import requests
3
 
4
+ API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
5
+ headers = {
6
+ "Authorization": f"Bearer {st.secrets['HF_API_TOKEN']}"
7
+ }
 
 
 
 
 
8
 
9
  st.set_page_config(page_title="Fitness Plan AI", layout="centered")
10
 
11
  st.title("🏋️ Fitness Plan AI Generator")
12
  st.write("Generate a personalized fitness plan using AI")
13
 
14
+ age = st.number_input("Age", 15, 80, 22)
 
15
  gender = st.selectbox("Gender", ["Male", "Female"])
16
  goal = st.selectbox("Fitness Goal", ["Weight Loss", "Muscle Gain", "General Fitness"])
17
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
18
  days = st.slider("Workout Days per Week", 1, 7, 4)
19
 
20
+ def query(payload):
21
+ response = requests.post(API_URL, headers=headers, json=payload)
22
+ return response.json()
23
+
24
  if st.button("Generate Fitness Plan"):
25
  prompt = (
26
  f"Create a {days}-day fitness workout plan for a "
 
30
  f"Include warm-up, main workout, and cool-down."
31
  )
32
 
33
+ with st.spinner("Generating plan..."):
34
+ output = query({"inputs": prompt})
35
  st.success("✅ Your Fitness Plan")
36
+ st.write(outp