Skip to content

Commit deec35a

Browse files
authored
Merge pull request #2 from kaayar/main
Add gemini
2 parents 289b22c + 4c381aa commit deec35a

File tree

3 files changed

+447
-0
lines changed

3 files changed

+447
-0
lines changed

health_assist.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
import streamlit as st
3+
import pandas as pd
4+
import google.generativeai as genai
5+
6+
# Set the background image
7+
st.set_page_config(page_title="Quantified Self Chat", page_icon=":bar_chart:", layout="wide", initial_sidebar_state="expanded", menu_items=None)
8+
st.markdown(
9+
"""
10+
<style>
11+
body {
12+
background-image: url("quantified_image.jpg");
13+
background-size: cover;
14+
}
15+
</style>
16+
""",
17+
unsafe_allow_html=True,
18+
)
19+
20+
# Set the environment variable
21+
os.environ['GOOGLE_API_KEY'] = st.secrets["GOOGLE_API_KEY"]
22+
23+
def configure_model():
24+
"""Configure the generative model."""
25+
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
26+
return genai.GenerativeModel('gemini-pro')
27+
28+
def load_data():
29+
"""Load and preprocess the data."""
30+
uploaded_file = st.file_uploader("Choose a CSV file", type='csv')
31+
if uploaded_file is not None:
32+
df = pd.read_csv(uploaded_file, delimiter=',')
33+
df.drop(columns=['Person ID', 'Gender', 'Age', 'Occupation', 'Nurse ID'], inplace=True)
34+
return df.to_dict(orient='list')
35+
36+
def get_response(model, user_input, sleep_data):
37+
"""Generate a response from the model."""
38+
input_prompt = f"This is user asking : {user_input}\n\n based on what user asked, this is the sleep data: {str(sleep_data)}\n\n Give me short quantified answer in 1 to 5 lines only based on the sleep data: "
39+
return model.generate_content(input_prompt).text
40+
41+
def main():
42+
"""Main function to run the app."""
43+
st.title('The Quantified Self Chat')
44+
model = configure_model()
45+
sleep_data = load_data()
46+
47+
if sleep_data is not None:
48+
49+
st.subheader('Sleep dataset')
50+
st.write(pd.DataFrame.from_dict(sleep_data))
51+
52+
# Initialize session state for chat history
53+
if 'chat_history' not in st.session_state:
54+
st.session_state['chat_history'] = []
55+
56+
user_input = st.text_input("Ask Questions", "")
57+
58+
if st.button("Submit"): # Check if user input is not empty
59+
response = get_response(model, user_input, sleep_data)
60+
# Update chat history
61+
st.session_state['chat_history'].append({"User": user_input, "Gemini Pro": response})
62+
63+
# Display chat history
64+
for chat in st.session_state['chat_history']:
65+
st.write(f"User: {chat['User']}")
66+
st.write(f"AI Assistant: {chat['Gemini Pro']}")
67+
68+
else:
69+
st.write("Please upload a CSV file to load the sleep data.")
70+
71+
if __name__ == "__main__":
72+
main()

quantified_image.jpg

147 KB
Loading

0 commit comments

Comments
 (0)