Safwanahmad619 commited on
Commit
3f0b79c
·
verified ·
1 Parent(s): a4edb10

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import anthropic
3
+ import os
4
+
5
+ # Function to call Claude AI API and get a personalized meal plan
6
+ def get_meal_plan(fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences):
7
+ anti_api_key = os.getenv('claude_api') # Replace with your actual API key or environment variable
8
+ client = anthropic.Anthropic(api_key=anti_api_key)
9
+
10
+ # Define the prompt to send to Claude AI
11
+ prompt = (
12
+ f"My fasting sugar level is {fasting_sugar} mg/dL, "
13
+ f"my pre-meal sugar level is {pre_meal_sugar} mg/dL, "
14
+ f"and my post-meal sugar level is {post_meal_sugar} mg/dL. "
15
+ f"My dietary preferences are {dietary_preferences}. "
16
+ "Please provide a personalized meal plan that can help me manage my blood sugar levels effectively."
17
+ )
18
+
19
+ # Call Claude AI API
20
+ message = client.messages.create(
21
+ model="claude-3-5-sonnet-20240620",
22
+ max_tokens=250,
23
+ temperature=0.7,
24
+ system="You are a world-class nutritionist who specializes in diabetes management.",
25
+ messages=[
26
+ {
27
+ "role": "user",
28
+ "content": prompt
29
+ }
30
+ ]
31
+ )
32
+
33
+ raw_context = message.content
34
+ meal_plan = raw_context[0].text
35
+ return meal_plan
36
+
37
+ # Gradio interface
38
+ def generate_meal_plan(fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences):
39
+ meal_plan = get_meal_plan(fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences)
40
+ return meal_plan
41
+
42
+ with gr.Blocks() as demo:
43
+ gr.Markdown("# Glucose Guardian")
44
+ gr.Markdown("**Glucose Guardian** is a personalized meal planning tool designed specifically for diabetic patients. By entering your sugar levels and dietary preferences, Glucose Guardian generates meal plans that are tailored to help you manage your blood sugar levels effectively.")
45
+
46
+ with gr.Row():
47
+ fasting_sugar = gr.Number(label="Fasting Sugar Levels (mg/dL)", value=0, min=0, max=500, step=1)
48
+ pre_meal_sugar = gr.Number(label="Pre-Meal Sugar Levels (mg/dL)", value=0, min=0, max=500, step=1)
49
+ post_meal_sugar = gr.Number(label="Post-Meal Sugar Levels (mg/dL)", value=0, min=0, max=500, step=1)
50
+
51
+ dietary_preferences = gr.Textbox(label="Dietary Preferences (e.g., vegetarian, low-carb)")
52
+
53
+ meal_plan_output = gr.Markdown()
54
+
55
+ generate_button = gr.Button("Generate Meal Plan")
56
+ generate_button.click(fn=generate_meal_plan, inputs=[fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences], outputs=meal_plan_output)
57
+
58
+ demo.launch()