Gluco-Guide / app.py
sal-maq's picture
Update app.py
088c32c verified
import anthropic
import os
import streamlit as st
# Load the API key from environment variables
api_key = os.getenv("ANTHROPIC_API_KEY")
# Initialize the Anthropics client
client = anthropic.Anthropic(api_key=api_key)
def meal_plan_generate(fasting_sugar_level, pre_meal_sugar, post_meal_sugar, dietary_preferences):
try:
# Construct the message prompt
prompt = f"I am a diabetic patient. My fasting sugar level is {fasting_sugar_level}, pre-meal sugar level is {pre_meal_sugar}, and post-meal sugar level is {post_meal_sugar}. My dietary preferences are {dietary_preferences}. Could you recommend some food recipes based on this information?"
# API call to generate meal plan using Messages API
response = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=400,
temperature=0,
system="You are a helpful medical assistant that provides food recommendations based on sugar levels and dietary preferences.",
prompt=prompt
)
# Process the response
if response and 'content' in response:
raw_context = response['content']
return raw_context if raw_context else "No content returned from the API."
else:
return "Unexpected response format from the API."
except Exception as e:
return f"An error occurred: {e}"
def main():
st.set_page_config(page_title="GlucoGuide", layout="wide")
st.title("🍎 GlucoGuide")
st.markdown("""
*GlucoGuide* is an innovative app designed to help you maintain a healthy lifestyle by providing personalized meal suggestions based on your sugar levels. Whether you are managing diabetes or simply aiming to improve your overall well-being, GlucoGuide is here to support you on your journey.
""")
st.sidebar.header("Input Details")
# Sidebar Inputs
fasting_sugar_level = st.sidebar.text_input("Fasting Sugar Level", placeholder="Enter your fasting sugar level")
pre_meal_sugar = st.sidebar.text_input("Pre-Meal Sugar Level", placeholder="Enter your pre-meal sugar level")
post_meal_sugar = st.sidebar.text_input("Post-Meal Sugar Level", placeholder="Enter your post-meal sugar level")
dietary_preferences = st.sidebar.text_area("Dietary Preferences", placeholder="Enter your dietary preferences")
st.subheader("💡 How to Use")
st.markdown("""
To get started with GlucoGuide, simply input your sugar levels using a glucose monitoring device or manually enter the readings. You can specify whether your sugar levels are fasting, pre-meal, or post-meal measurements. Additionally, the app allows you to provide information about your dietary preferences, such as vegetarian, vegan, or specific dietary restrictions.
Based on this information, GlucoGuide will generate meal recommendations that align with your dietary preferences, ensuring a balanced and enjoyable eating experience. Experience the convenience of having a personal health coach in your pocket with GlucoGuide. Take control of your health and make informed choices to achieve your wellness goals.
""")
if st.sidebar.button("🍽️ Generate Meal Plan"):
if not fasting_sugar_level or not pre_meal_sugar or not dietary_preferences:
st.error("Please provide all required inputs.")
else:
with st.spinner("Generating meal plan..."):
generated_meal_plan = meal_plan_generate(fasting_sugar_level, pre_meal_sugar, post_meal_sugar, dietary_preferences)
st.subheader("Meal Plan")
st.text(generated_meal_plan)
st.warning("""
**Warning**: GlucoGuide's AI-generated meal suggestions are intended to support your health journey, but always consult with healthcare professionals for personalized medical advice and guidance regarding your specific condition and dietary needs.
""")
st.markdown("**Developed by Salman Maqbool ❤️**")
if __name__ == "__main__":
main()