yhraje commited on
Commit
3879b79
·
verified ·
1 Parent(s): d8a3f4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -26
app.py CHANGED
@@ -5,10 +5,10 @@ from phi.tools.duckduckgo import DuckDuckGo
5
  from dotenv import load_dotenv
6
  import os
7
 
8
- # Load environment
9
  load_dotenv()
10
 
11
- # Agent definition
12
  nutrition_agent = Agent(
13
  name="nutrition_agent",
14
  model=Gemini(id="gemini-2.5-flash-preview-04-17"),
@@ -26,7 +26,7 @@ nutrition_agent = Agent(
26
  markdown=True
27
  )
28
 
29
- # Gradio input processing
30
  def generate_diet(name, age, gender, diet_type, location, health_issues, goals, likes, dislikes, calories):
31
  user_input = (
32
  f"My name is {name}. I am {age} years old, {gender}, {diet_type}, living in {location}. "
@@ -36,29 +36,42 @@ def generate_diet(name, age, gender, diet_type, location, health_issues, goals,
36
  "Please generate a personalized meal plan broken into breakfast, lunch, snacks, dinner. "
37
  "Also include a clear explanation of nutritional content and a conclusion for health advice."
38
  )
39
- return nutrition_agent.run(user_input)
40
 
41
- # Gradio interface
42
- iface = gr.Interface(
43
- fn=generate_diet,
44
- inputs=[
45
- gr.Textbox(label="Name"),
46
- gr.Textbox(label="Age"),
47
- gr.Radio(["Male", "Female", "Other"], label="Gender"),
48
- gr.Radio(["Vegetarian", "Non-Vegetarian"], label="Diet Type"),
49
- gr.Textbox(label="Location"),
50
- gr.Textbox(label="Health Issues"),
51
- gr.Textbox(label="Fitness Goals"),
52
- gr.Textbox(label="Foods You Like"),
53
- gr.Textbox(label="Foods You Dislike"),
54
- gr.Textbox(label="Daily Calorie Requirement"),
55
- ],
56
- outputs=gr.Markdown(label="🧠 Your Personalized Nutrition Plan"),
57
- title="🥗 Smartest AI Nutrition Assistant",
58
- description="Get a fully personalized diet plan with nutritional breakdown using AI.",
59
- theme="soft"
60
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- # Launch the UI
63
  if __name__ == "__main__":
64
- iface.launch()
 
5
  from dotenv import load_dotenv
6
  import os
7
 
8
+ # Load environment variables
9
  load_dotenv()
10
 
11
+ # Setup agent
12
  nutrition_agent = Agent(
13
  name="nutrition_agent",
14
  model=Gemini(id="gemini-2.5-flash-preview-04-17"),
 
26
  markdown=True
27
  )
28
 
29
+ # Function to call agent
30
  def generate_diet(name, age, gender, diet_type, location, health_issues, goals, likes, dislikes, calories):
31
  user_input = (
32
  f"My name is {name}. I am {age} years old, {gender}, {diet_type}, living in {location}. "
 
36
  "Please generate a personalized meal plan broken into breakfast, lunch, snacks, dinner. "
37
  "Also include a clear explanation of nutritional content and a conclusion for health advice."
38
  )
 
39
 
40
+ # Run the agent
41
+ result = nutrition_agent.run(user_input)
42
+
43
+ # Ensure output is readable
44
+ if hasattr(result, "content"):
45
+ return result.content
46
+ elif isinstance(result, str):
47
+ return result
48
+ else:
49
+ return "⚠️ Unexpected response format. Please try again."
50
+
51
+ # Gradio UI
52
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
53
+ gr.Markdown("## 🥗 Smartest AI Nutrition Assistant")
54
+ with gr.Row():
55
+ with gr.Column():
56
+ name = gr.Textbox(label="Name")
57
+ age = gr.Textbox(label="Age")
58
+ gender = gr.Radio(["Male", "Female", "Other"], label="Gender")
59
+ diet_type = gr.Radio(["Vegetarian", "Non-Vegetarian"], label="Diet Type")
60
+ location = gr.Textbox(label="Location")
61
+ health_issues = gr.Textbox(label="Health Issues")
62
+ goals = gr.Textbox(label="Fitness Goals")
63
+ likes = gr.Textbox(label="Foods You Like")
64
+ dislikes = gr.Textbox(label="Foods You Dislike")
65
+ calories = gr.Textbox(label="Daily Calorie Requirement")
66
+ submit = gr.Button("Get Diet Plan")
67
+ with gr.Column():
68
+ output = gr.Markdown(label="🧠 Your Personalized Diet Plan")
69
+
70
+ submit.click(
71
+ fn=generate_diet,
72
+ inputs=[name, age, gender, diet_type, location, health_issues, goals, likes, dislikes, calories],
73
+ outputs=output
74
+ )
75
 
 
76
  if __name__ == "__main__":
77
+ demo.launch()