Safwanahmad619 commited on
Commit
563c81f
·
verified ·
1 Parent(s): efa6836

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -37
main.py CHANGED
@@ -1,19 +1,10 @@
1
- import streamlit as st
2
- import os
3
  import gradio as gr
4
- import whisper
5
- from gtts import gTTS
6
- import io
7
- from groq import Groq
8
-
9
-
10
  import anthropic
11
-
12
- api_key = st.secrets["my-key"]
13
 
14
  # Function to call Claude AI API and get a personalized meal plan
15
- def get_meal_plan(api_key, fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences):
16
- # Initialize the Claude AI client with the provided API key
17
  client = anthropic.Anthropic(api_key=api_key)
18
 
19
  # Define the prompt to send to Claude AI
@@ -40,30 +31,28 @@ def get_meal_plan(api_key, fasting_sugar, pre_meal_sugar, post_meal_sugar, dieta
40
  )
41
 
42
  raw_context = message.content
43
- itinerary = raw_context[0].text
44
- return itinerary
45
-
46
- # Streamlit app
47
- st.title("Glucose Guardian")
48
-
49
- st.write("""
50
- **Glucose Guardian** is a personalized meal planning tool designed specifically for diabetic patients.
51
- By entering your sugar levels and dietary preferences, Glucose Guardian generates meal plans that are
52
- tailored to help you manage your blood sugar levels effectively.
53
- """)
54
 
55
- # Sidebar inputs for sugar levels and dietary preferences
56
- st.sidebar.header("Enter Your Details")
 
 
57
 
58
- fasting_sugar = st.sidebar.number_input("Fasting Sugar Levels (mg/dL)", min_value=0, max_value=500, step=1)
59
- pre_meal_sugar = st.sidebar.number_input("Pre-Meal Sugar Levels (mg/dL)", min_value=0, max_value=500, step=1)
60
- post_meal_sugar = st.sidebar.number_input("Post-Meal Sugar Levels (mg/dL)", min_value=0, max_value=500, step=1)
61
-
62
- dietary_preferences = st.sidebar.text_input("Dietary Preferences (e.g., vegetarian, low-carb)")
63
-
64
- # Generate meal plan button
65
- if st.sidebar.button("Generate Meal Plan"):
66
- meal_plan = get_meal_plan(api_key, fasting_sugar, pre_meal_sugar, post_meal_sugar, dietary_preferences)
67
- st.write("Based on your sugar levels and dietary preferences, here is a personalized meal plan:")
68
- st.markdown(meal_plan)
69
-
 
 
 
 
 
 
 
 
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
+ api_key = os.getenv('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') # Replace with your actual API key or environment variable
8
  client = anthropic.Anthropic(api_key=api_key)
9
 
10
  # Define the prompt to send to Claude AI
 
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()