Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
#
|
| 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 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
# Launch the UI
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
|
|
|
|
| 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()
|