File size: 4,047 Bytes
2e82482
 
088c32c
2e82482
4403fbc
 
2e82482
2e7a7c5
 
2e82482
 
4403fbc
0abd7f0
088c32c
0abd7f0
4180fd5
2e7a7c5
 
 
 
 
088c32c
4403fbc
2e7a7c5
4403fbc
2e7a7c5
 
f230a5b
 
 
4403fbc
 
 
cc2ec0d
 
 
 
 
 
2e7a7c5
4180fd5
2e7a7c5
4180fd5
 
 
 
 
 
cc2ec0d
 
 
 
 
 
 
4180fd5
cc2ec0d
 
 
 
 
 
 
2e82482
0abd7f0
088c32c
cc2ec0d
 
db8c3f3
cc2ec0d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()