Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +75 -0
- requirements.txt +11 -0
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import google.generativeai as genai
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
os.environ["google_API_KEY"] = 'AIzaSyAGB5JvQRItM2CeZjLhJp-KKljxfuPBOzo'
|
| 9 |
+
genai.configure(api_key=os.getenv("google_API_KEY"))
|
| 10 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 11 |
+
chat = model.start_chat(history=[])
|
| 12 |
+
def get_gemini_response(question, gender, age, weight, height, activity_level, goals, dietary_restrictions):
|
| 13 |
+
text = f'Act as a fitness trainer and give a short but to the point answer according to the given information that I am {age} years old {gender}, my weight is {weight} kg, my height is {height}cm, i am {activity_level}, my goal is to {goals} and i am {dietary_restrictions}. my question is that {question}'
|
| 14 |
+
response =chat.send_message(text,stream=True)
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
+
st.set_page_config(page_title="Fitness AI ChatBot", page_icon="🏋️♀️")
|
| 18 |
+
|
| 19 |
+
st.title("🔹🔷Fitee🔷🔹")
|
| 20 |
+
st.write("Made with ❤️ by Mainak")
|
| 21 |
+
with st.sidebar:
|
| 22 |
+
gender = st.selectbox("Gender", ["male", "female"])
|
| 23 |
+
age = st.number_input("Age", min_value=0, max_value=150, value=30)
|
| 24 |
+
weight = st.number_input("Weight (kg)", min_value=0.0, step=1.0, value=70.0)
|
| 25 |
+
height = st.number_input("Height (cm)", min_value=0.0,step=1.0, value=170.0)
|
| 26 |
+
activity_level = st.selectbox("Activity Level", ["Sedentary", "Lightly Active", "Moderately Active", "Very Active"])
|
| 27 |
+
goals = st.radio("Goals", ["Loss Weight", "Maintain Weight", "Gain Weight"])
|
| 28 |
+
dietary_restrictions = st.multiselect("Dietary Restrictions", ["Vegetarian", "Vegan", "Gluten-Free", "Dairy-Free"])
|
| 29 |
+
|
| 30 |
+
if 'button_pressed' not in st.session_state:
|
| 31 |
+
st.session_state.button_pressed = False
|
| 32 |
+
|
| 33 |
+
# Button to start conversation
|
| 34 |
+
start_conversation = st.button("Start Conversation")
|
| 35 |
+
|
| 36 |
+
if start_conversation or st.session_state.button_pressed:
|
| 37 |
+
st.session_state.button_pressed = True
|
| 38 |
+
if "messages" not in st.session_state:
|
| 39 |
+
st.session_state.messages = []
|
| 40 |
+
|
| 41 |
+
# Display chat messages from history on app rerun
|
| 42 |
+
for message in st.session_state.messages:
|
| 43 |
+
with st.chat_message(message["role"]):
|
| 44 |
+
st.markdown(message["content"])
|
| 45 |
+
if prompt := st.chat_input("What is up?"):
|
| 46 |
+
# Display user message in chat message container
|
| 47 |
+
with st.chat_message("user"):
|
| 48 |
+
st.markdown(prompt)
|
| 49 |
+
# Add user message to chat history
|
| 50 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 51 |
+
if prompt is None:
|
| 52 |
+
response='Ask me anything about Fitness'
|
| 53 |
+
else:
|
| 54 |
+
with st.spinner('Typping...'):
|
| 55 |
+
re = get_gemini_response(str(prompt), gender, age, weight, height, activity_level, goals, dietary_restrictions)
|
| 56 |
+
response = ''
|
| 57 |
+
for chunk in re:
|
| 58 |
+
for ch in chunk.text.split(' '):
|
| 59 |
+
response += ch + ' '
|
| 60 |
+
# res = []
|
| 61 |
+
# for chunk in re:
|
| 62 |
+
# res.append(chunk.text)
|
| 63 |
+
# st.write(chunk.text)
|
| 64 |
+
# print("_"*80)
|
| 65 |
+
# re = re["output_text"]
|
| 66 |
+
# re=return_response(str(prompt),document_search,chain)
|
| 67 |
+
# response = re
|
| 68 |
+
# Display assistant response in chat message container
|
| 69 |
+
with st.chat_message("assistant"):
|
| 70 |
+
if type(response)==str:
|
| 71 |
+
st.markdown(response)
|
| 72 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 73 |
+
else:
|
| 74 |
+
st.markdown(response)
|
| 75 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
openai
|
| 3 |
+
PyPDF2
|
| 4 |
+
faiss-cpu
|
| 5 |
+
tiktoken
|
| 6 |
+
pinecone-client
|
| 7 |
+
streamlit
|
| 8 |
+
pyautogui
|
| 9 |
+
streamlit_autorefresh
|
| 10 |
+
google-generativeai
|
| 11 |
+
langchain_google_genai
|