Spaces:
Sleeping
Sleeping
Pratik Dwivedi
commited on
Commit
•
cb84364
1
Parent(s):
1d64b5f
personal
Browse files
app.py
CHANGED
@@ -2,6 +2,16 @@ import streamlit as st
|
|
2 |
import openai
|
3 |
|
4 |
# Function to interact with GPT-3 model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def ask_gpt3_personalized(prompt, height_cm, weight_kg, age):
|
6 |
response = openai.ChatCompletion.create(
|
7 |
model="gpt-3.5-turbo",
|
@@ -25,16 +35,14 @@ def ask_gpt3(prompt):
|
|
25 |
# Main function to run the Streamlit app
|
26 |
def main():
|
27 |
st.title("Fitness Chatbot")
|
28 |
-
|
29 |
-
# add a sibebar that can take in user input for the chatbot prompt and the API key
|
30 |
st.sidebar.title("Personal Information")
|
31 |
-
# this is a sceret key that should not be shared with anyone
|
32 |
-
# openai.api_key = st.sidebar.text_input("Your OpenAI API Key here", "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")
|
33 |
openai.api_key = st.sidebar.text_input("OpenAI API Key", type="password", value = "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")
|
34 |
-
height_cm = st.sidebar.number_input("Height (cm)", 0,
|
35 |
-
weight_kg = st.sidebar.number_input("Weight (kg)", 0,
|
36 |
age = st.sidebar.number_input("Age", 0, 100)
|
37 |
-
|
|
|
|
|
38 |
|
39 |
# Initialize conversation history
|
40 |
if "messages" not in st.session_state:
|
@@ -51,6 +59,8 @@ def main():
|
|
51 |
# Get chatbot response
|
52 |
if height_cm and weight_kg and age:
|
53 |
chatbot_response = ask_gpt3_personalized(user_input, height_cm, weight_kg, age)
|
|
|
|
|
54 |
else:
|
55 |
chatbot_response = ask_gpt3(user_input)
|
56 |
|
@@ -62,9 +72,5 @@ def main():
|
|
62 |
with st.chat_message(message["role"]):
|
63 |
st.markdown(message["content"])
|
64 |
|
65 |
-
# Clear the chat input
|
66 |
-
st.session_state["chat_input"] = ""
|
67 |
-
|
68 |
-
# Run the main function
|
69 |
if __name__ == "__main__":
|
70 |
main()
|
|
|
2 |
import openai
|
3 |
|
4 |
# Function to interact with GPT-3 model
|
5 |
+
def ask_gpt3_personalized_extra(prompt, height_cm, weight_kg, age, fitness_goal, Activity_Level, dietary_restrictions):
|
6 |
+
response = openai.ChatCompletion.create(
|
7 |
+
model="gpt-3.5-turbo",
|
8 |
+
messages=[
|
9 |
+
{"role": "system", "content": "You are a chatbot that will answer queries related to fitness and nutrition. The chatbot should understand questions about workout routines, dietary advice, and general fitness tips. Chatbot will offer personalized workout and diet plans based on user inputs such as body type, fitness goals, and dietary restrictions.{messages}"},
|
10 |
+
{"role": "user", "content": "my height is " + str(height_cm) + " cm, my weight is " + str(weight_kg) + " kg, and I am " + str(age) + " years old. I want to " + fitness_goal.lower() + " and I am " + Activity_Level.lower() + " and I have " + ", ".join(dietary_restrictions) + " dietary restrictions."+prompt},
|
11 |
+
]
|
12 |
+
)
|
13 |
+
return response['choices'][0]['message']['content']
|
14 |
+
|
15 |
def ask_gpt3_personalized(prompt, height_cm, weight_kg, age):
|
16 |
response = openai.ChatCompletion.create(
|
17 |
model="gpt-3.5-turbo",
|
|
|
35 |
# Main function to run the Streamlit app
|
36 |
def main():
|
37 |
st.title("Fitness Chatbot")
|
|
|
|
|
38 |
st.sidebar.title("Personal Information")
|
|
|
|
|
39 |
openai.api_key = st.sidebar.text_input("OpenAI API Key", type="password", value = "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")
|
40 |
+
height_cm = st.sidebar.number_input("Height (cm)", 0, 250)
|
41 |
+
weight_kg = st.sidebar.number_input("Weight (kg)", 0, 500)
|
42 |
age = st.sidebar.number_input("Age", 0, 100)
|
43 |
+
fitness_goal = st.sidebar.selectbox("Fitness Goal", ["Lose Weight", "Gain Muscle", "Maintain Weight", "Improve Endurance"])
|
44 |
+
Activity_Level = st.sidebar.selectbox("Activity Level", ["Sedentary", "Lightly Active", "Moderately Active", "Very Active", "Extra Active"])
|
45 |
+
dietary_restrictions = st.sidebar.multiselect("Dietary Restrictions", ["Vegetarian", "Vegan", "Gluten Free", "Lactose Free", "Keto", "Paleo", "None"])
|
46 |
|
47 |
# Initialize conversation history
|
48 |
if "messages" not in st.session_state:
|
|
|
59 |
# Get chatbot response
|
60 |
if height_cm and weight_kg and age:
|
61 |
chatbot_response = ask_gpt3_personalized(user_input, height_cm, weight_kg, age)
|
62 |
+
elif height_cm and weight_kg and age and fitness_goal and Activity_Level and dietary_restrictions:
|
63 |
+
chatbot_response = ask_gpt3_personalized_extra(user_input, height_cm, weight_kg, age, fitness_goal, Activity_Level, dietary_restrictions)
|
64 |
else:
|
65 |
chatbot_response = ask_gpt3(user_input)
|
66 |
|
|
|
72 |
with st.chat_message(message["role"]):
|
73 |
st.markdown(message["content"])
|
74 |
|
|
|
|
|
|
|
|
|
75 |
if __name__ == "__main__":
|
76 |
main()
|