Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #2

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions health_assist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import streamlit as st
import pandas as pd
import google.generativeai as genai

# Set the background image
st.set_page_config(page_title="Quantified Self Chat", page_icon=":bar_chart:", layout="wide", initial_sidebar_state="expanded", menu_items=None)
st.markdown(
"""
<style>
body {
background-image: url("quantified_image.jpg");
background-size: cover;
}
</style>
""",
unsafe_allow_html=True,
)

# Set the environment variable
os.environ['GOOGLE_API_KEY'] = st.secrets["GOOGLE_API_KEY"]

def configure_model():
"""Configure the generative model."""
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
return genai.GenerativeModel('gemini-pro')

def load_data():
"""Load and preprocess the data."""
uploaded_file = st.file_uploader("Choose a CSV file", type='csv')
if uploaded_file is not None:
df = pd.read_csv(uploaded_file, delimiter=',')
df.drop(columns=['Person ID', 'Gender', 'Age', 'Occupation', 'Nurse ID'], inplace=True)
return df.to_dict(orient='list')

def get_response(model, user_input, sleep_data):
"""Generate a response from the model."""
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: "
return model.generate_content(input_prompt).text

def main():
"""Main function to run the app."""
st.title('The Quantified Self Chat')
model = configure_model()
sleep_data = load_data()

if sleep_data is not None:

st.subheader('Sleep dataset')
st.write(pd.DataFrame.from_dict(sleep_data))

# Initialize session state for chat history
if 'chat_history' not in st.session_state:
st.session_state['chat_history'] = []

user_input = st.text_input("Ask Questions", "")

if st.button("Submit"): # Check if user input is not empty
response = get_response(model, user_input, sleep_data)
# Update chat history
st.session_state['chat_history'].append({"User": user_input, "Gemini Pro": response})

# Display chat history
for chat in st.session_state['chat_history']:
st.write(f"User: {chat['User']}")
st.write(f"AI Assistant: {chat['Gemini Pro']}")

else:
st.write("Please upload a CSV file to load the sleep data.")

if __name__ == "__main__":
main()
Binary file added quantified_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading