Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
|
| 4 |
-
# Access the OpenAI API key from
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
-
st.title("
|
| 8 |
|
| 9 |
-
# User inputs
|
| 10 |
-
st.subheader("
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
prompt_text = (
|
| 18 |
-
f"
|
| 19 |
-
f"
|
| 20 |
)
|
| 21 |
|
| 22 |
# Call the OpenAI API for text generation
|
|
@@ -24,16 +33,17 @@ if st.button('Generate AI Lead Magnet Ideas'):
|
|
| 24 |
response_text = openai.ChatCompletion.create(
|
| 25 |
model="gpt-4",
|
| 26 |
messages=[
|
| 27 |
-
{"role": "system", "content": "You are an
|
| 28 |
{"role": "user", "content": prompt_text}
|
| 29 |
]
|
| 30 |
)
|
| 31 |
-
|
| 32 |
except Exception as e:
|
| 33 |
-
|
| 34 |
|
| 35 |
-
# Display the
|
| 36 |
-
st.markdown("###
|
| 37 |
-
st.write(
|
| 38 |
|
| 39 |
-
#
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
|
| 4 |
+
# Access the OpenAI API key from environment variables or secrets
|
| 5 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 6 |
|
| 7 |
+
st.title("Personalized 6-Month Fitness and Health Plan Generator")
|
| 8 |
|
| 9 |
+
# User inputs
|
| 10 |
+
st.subheader("About You")
|
| 11 |
+
name = st.text_input("Your Name", placeholder="Enter your name")
|
| 12 |
+
age = st.number_input("Your Age", min_value=12, max_value=100, step=1)
|
| 13 |
+
gender = st.selectbox("Your Gender", ["Female", "Male", "Prefer not to say"])
|
| 14 |
|
| 15 |
+
st.subheader("Current Fitness and Health Status")
|
| 16 |
+
current_fitness_level = st.selectbox("Your Current Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 17 |
+
current_health_issues = st.text_area("Current Health Issues", placeholder="Any known health issues or concerns")
|
| 18 |
+
dietary_preferences = st.text_area("Dietary Preferences", placeholder="e.g., Vegan, Gluten-free, Keto, No preferences")
|
| 19 |
+
|
| 20 |
+
st.subheader("Your Fitness Goals")
|
| 21 |
+
fitness_goals = st.multiselect("Select Your Fitness Goals", ["Weight loss", "Muscle gain", "Endurance improvement", "Flexibility", "General well-being"])
|
| 22 |
+
goal_timeframe = st.selectbox("Goal Timeframe", ["3 months", "6 months", "1 year"])
|
| 23 |
+
|
| 24 |
+
if st.button('Generate My Fitness Plan'):
|
| 25 |
+
# Construct the prompt for the AI
|
| 26 |
prompt_text = (
|
| 27 |
+
f"Create a personalized 6-month fitness and health plan for {name}, a {age}-year-old {gender} with {current_fitness_level} fitness level. "
|
| 28 |
+
f"Health issues: {current_health_issues}. Dietary preferences: {dietary_preferences}. Fitness goals: {', '.join(fitness_goals)} over {goal_timeframe}."
|
| 29 |
)
|
| 30 |
|
| 31 |
# Call the OpenAI API for text generation
|
|
|
|
| 33 |
response_text = openai.ChatCompletion.create(
|
| 34 |
model="gpt-4",
|
| 35 |
messages=[
|
| 36 |
+
{"role": "system", "content": "You are an AI fitness coach."},
|
| 37 |
{"role": "user", "content": prompt_text}
|
| 38 |
]
|
| 39 |
)
|
| 40 |
+
fitness_plan = response_text.choices[0].message['content']
|
| 41 |
except Exception as e:
|
| 42 |
+
fitness_plan = f"Error in generating fitness plan: {e}"
|
| 43 |
|
| 44 |
+
# Display the fitness plan
|
| 45 |
+
st.markdown("### Your Personalized 6-Month Fitness Plan")
|
| 46 |
+
st.write(fitness_plan)
|
| 47 |
|
| 48 |
+
# Disclaimer
|
| 49 |
+
st.write("Disclaimer: This tool provides suggestions based on AI-generated content. Please consult with a healthcare provider or a professional fitness trainer before starting any new fitness program.")
|