Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,40 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import anthropic
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Load the API key from environment variables
|
| 6 |
api_key = os.getenv("ANTHROPIC_API_KEY")
|
| 7 |
|
| 8 |
-
# Initialize the
|
| 9 |
-
client = anthropic.
|
| 10 |
|
| 11 |
def meal_plan_generate(fasting_sugar_level, pre_meal_sugar, post_meal_sugar, dietary_preferences):
|
| 12 |
try:
|
| 13 |
# Construct the message prompt
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# API call to generate meal plan using Messages API
|
| 26 |
-
response = client.
|
| 27 |
-
model="claude-3-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
)
|
| 32 |
-
|
| 33 |
# Process the response
|
| 34 |
-
if response and '
|
| 35 |
-
raw_context = response['
|
| 36 |
return raw_context if raw_context else "No content returned from the API."
|
| 37 |
else:
|
| 38 |
return "Unexpected response format from the API."
|
|
@@ -40,21 +42,21 @@ def meal_plan_generate(fasting_sugar_level, pre_meal_sugar, post_meal_sugar, die
|
|
| 40 |
return f"An error occurred: {e}"
|
| 41 |
|
| 42 |
def main():
|
|
|
|
| 43 |
st.set_page_config(page_title="GlucoGuide", layout="wide")
|
| 44 |
st.title("🍎 GlucoGuide")
|
| 45 |
st.markdown("""
|
| 46 |
*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.
|
| 47 |
""")
|
| 48 |
-
|
| 49 |
st.sidebar.header("Input Details")
|
| 50 |
-
|
| 51 |
# Sidebar Inputs
|
| 52 |
fasting_sugar_level = st.sidebar.text_input("Fasting Sugar Level", placeholder="Enter your fasting sugar level")
|
| 53 |
pre_meal_sugar = st.sidebar.text_input("Pre-Meal Sugar Level", placeholder="Enter your pre-meal sugar level")
|
| 54 |
post_meal_sugar = st.sidebar.text_input("Post-Meal Sugar Level", placeholder="Enter your post-meal sugar level")
|
| 55 |
dietary_preferences = st.sidebar.text_area("Dietary Preferences", placeholder="Enter your dietary preferences")
|
| 56 |
|
| 57 |
-
# Main content
|
| 58 |
st.subheader("💡 How to Use")
|
| 59 |
st.markdown("""
|
| 60 |
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.
|
|
|
|
|
|
|
| 1 |
import anthropic
|
| 2 |
import os
|
| 3 |
|
| 4 |
# Load the API key from environment variables
|
| 5 |
api_key = os.getenv("ANTHROPIC_API_KEY")
|
| 6 |
|
| 7 |
+
# Initialize the Anthropics client
|
| 8 |
+
client = anthropic.Anthropic(api_key=api_key)
|
| 9 |
|
| 10 |
def meal_plan_generate(fasting_sugar_level, pre_meal_sugar, post_meal_sugar, dietary_preferences):
|
| 11 |
try:
|
| 12 |
# Construct the message prompt
|
| 13 |
+
messages = [
|
| 14 |
+
{
|
| 15 |
+
"role": "system",
|
| 16 |
+
"content": "You are a helpful medical assistant that provides food recommendations based on sugar levels and dietary preferences."
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"role": "user",
|
| 20 |
+
"content": "I am a diabetic patient. My fasting sugar level is {}, pre-meal sugar level is {}, and post-meal sugar level is {}. My dietary preferences are {}. Could you recommend some food recipes based on this information?".format(
|
| 21 |
+
fasting_sugar_level, pre_meal_sugar, post_meal_sugar, dietary_preferences
|
| 22 |
+
)
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
|
| 26 |
# API call to generate meal plan using Messages API
|
| 27 |
+
response = client.messages.create(
|
| 28 |
+
model="claude-3-5-sonnet-20240620",
|
| 29 |
+
max_tokens=400,
|
| 30 |
+
temperature=0,
|
| 31 |
+
system="You are a helpful medical assistant that provides food recommendations based on sugar levels and dietary preferences.",
|
| 32 |
+
messages=messages
|
| 33 |
)
|
| 34 |
+
|
| 35 |
# Process the response
|
| 36 |
+
if response and 'content' in response:
|
| 37 |
+
raw_context = response['content']
|
| 38 |
return raw_context if raw_context else "No content returned from the API."
|
| 39 |
else:
|
| 40 |
return "Unexpected response format from the API."
|
|
|
|
| 42 |
return f"An error occurred: {e}"
|
| 43 |
|
| 44 |
def main():
|
| 45 |
+
import streamlit as st
|
| 46 |
st.set_page_config(page_title="GlucoGuide", layout="wide")
|
| 47 |
st.title("🍎 GlucoGuide")
|
| 48 |
st.markdown("""
|
| 49 |
*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.
|
| 50 |
""")
|
| 51 |
+
|
| 52 |
st.sidebar.header("Input Details")
|
| 53 |
+
|
| 54 |
# Sidebar Inputs
|
| 55 |
fasting_sugar_level = st.sidebar.text_input("Fasting Sugar Level", placeholder="Enter your fasting sugar level")
|
| 56 |
pre_meal_sugar = st.sidebar.text_input("Pre-Meal Sugar Level", placeholder="Enter your pre-meal sugar level")
|
| 57 |
post_meal_sugar = st.sidebar.text_input("Post-Meal Sugar Level", placeholder="Enter your post-meal sugar level")
|
| 58 |
dietary_preferences = st.sidebar.text_area("Dietary Preferences", placeholder="Enter your dietary preferences")
|
| 59 |
|
|
|
|
| 60 |
st.subheader("💡 How to Use")
|
| 61 |
st.markdown("""
|
| 62 |
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.
|