Spaces:
Running
Running
anunay.aatipamula commited on
Commit ·
ec0c688
1
Parent(s): b2c9ff2
base skeleton
Browse files- .gitignore +3 -0
- app.py +38 -0
- meal_planner_api/__init__.py +0 -0
- meal_planner_api/connect_llm_api.py +19 -0
- meal_planner_api/create_meal_plan.py +26 -0
- meal_planner_api/utils.py +7 -0
- mealplanner.ipynb +102 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/.ipynb_checkpoints/
|
| 2 |
+
/.idea/
|
| 3 |
+
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Import your meal planning API or logic here
|
| 4 |
+
from meal_planner_api import create_meal_plan # Replace with your actual API or logic
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def generate_meal_plan(parameters):
|
| 8 |
+
# Call your API or logic to generate the meal plan based on the parameters
|
| 9 |
+
meal_plan = create_meal_plan.generate(parameters)
|
| 10 |
+
return meal_plan
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Define input elements for user input
|
| 14 |
+
inputs = [
|
| 15 |
+
gr.Textbox(lines=5,
|
| 16 |
+
placeholder="Enter your personal information (age, gender, weight, height, activity level, dietary "
|
| 17 |
+
"preferences, allergies)"),
|
| 18 |
+
gr.Textbox(lines=4, placeholder="Enter your health goals (weight loss, muscle gain, health markers)"),
|
| 19 |
+
gr.Textbox(lines=3, placeholder="Enter your food preferences (likes, dislikes, cuisines)"),
|
| 20 |
+
gr.Textbox(lines=2, placeholder="Enter meal frequency and timing"),
|
| 21 |
+
gr.Textbox(lines=2, placeholder="Enter cooking skills and preferences"),
|
| 22 |
+
gr.Textbox(lines=1, placeholder="Enter your budget for groceries"),
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
# Define output elements to display the meal plan
|
| 26 |
+
outputs = [
|
| 27 |
+
gr.Textbox(label="Generated Meal Plan"),
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
# Launch the Gradio app
|
| 31 |
+
interface = gr.Interface(
|
| 32 |
+
fn=generate_meal_plan,
|
| 33 |
+
inputs=inputs,
|
| 34 |
+
outputs=outputs,
|
| 35 |
+
title="Personalized Meal Plan Generator",
|
| 36 |
+
description="Get a customized meal plan tailored to your needs and preferences.",
|
| 37 |
+
)
|
| 38 |
+
interface.launch()
|
meal_planner_api/__init__.py
ADDED
|
File without changes
|
meal_planner_api/connect_llm_api.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import utils
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def generate_content(text: str):
|
| 7 |
+
GOOGLE_API_KEY = 'AIzaSyA2siKQix1_QLHi9jq6NH3MnO-wQR4zzMU'
|
| 8 |
+
model = connect()
|
| 9 |
+
response = model.generate_content(text)
|
| 10 |
+
return utils.to_markdown(response.text)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def connect():
|
| 14 |
+
API_KEY = os.environ.get("GENAI_API_KEY")
|
| 15 |
+
genai.configure(api_key=API_KEY)
|
| 16 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 17 |
+
return model
|
| 18 |
+
|
| 19 |
+
|
meal_planner_api/create_meal_plan.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def generate(parameters):
|
| 2 |
+
"""Generates a meal plan based on user-provided parameters."""
|
| 3 |
+
|
| 4 |
+
# 1. Extract relevant information from user input
|
| 5 |
+
age = parameters["age"]
|
| 6 |
+
gender = parameters["gender"]
|
| 7 |
+
weight = parameters["weight"]
|
| 8 |
+
# ... Extract other parameters
|
| 9 |
+
|
| 10 |
+
# 2. Calculate calorie and macronutrient requirements
|
| 11 |
+
daily_calories = calculate_calorie_needs(parameters)
|
| 12 |
+
macro_goals = calculate_macro_goals(parameters)
|
| 13 |
+
|
| 14 |
+
# 3. Filter recipes based on dietary preferences, allergies, and macronutrients
|
| 15 |
+
filtered_recipes = filter_recipes(recipes, parameters)
|
| 16 |
+
|
| 17 |
+
# 4. Generate meal plan structure (assign recipes to meals and days)
|
| 18 |
+
meal_plan = create_meal_schedule(filtered_recipes, daily_calories, macro_goals, parameters)
|
| 19 |
+
|
| 20 |
+
# 5. Refine meal plan based on cooking skills, time constraints, and budget
|
| 21 |
+
meal_plan = adjust_meal_plan(meal_plan, parameters)
|
| 22 |
+
|
| 23 |
+
# 6. Format meal plan output (structure as needed for Gradio app)
|
| 24 |
+
meal_plan_output = format_meal_plan(meal_plan)
|
| 25 |
+
|
| 26 |
+
return meal_plan_output
|
meal_planner_api/utils.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import textwrap
|
| 2 |
+
from IPython.display import Markdown
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def to_markdown(text):
|
| 6 |
+
text = text.replace('•', ' *')
|
| 7 |
+
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
|
mealplanner.ipynb
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 8,
|
| 6 |
+
"id": "07f0c4f3-7770-46b1-b22b-ccfc9588ea81",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import gradio as gr\n",
|
| 11 |
+
"from meal_planner_api import create_meal_plan\n",
|
| 12 |
+
"\n"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": 9,
|
| 18 |
+
"id": "3639a70f-8b97-456a-b31c-541086435fa6",
|
| 19 |
+
"metadata": {},
|
| 20 |
+
"outputs": [],
|
| 21 |
+
"source": [
|
| 22 |
+
"def greet(name):\n",
|
| 23 |
+
" return \"Hello \" + name + \"!\"\n",
|
| 24 |
+
"\n"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": 10,
|
| 30 |
+
"id": "6d7091f8-3882-438c-b2c8-b1d57296772f",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [
|
| 33 |
+
{
|
| 34 |
+
"name": "stdout",
|
| 35 |
+
"output_type": "stream",
|
| 36 |
+
"text": [
|
| 37 |
+
"Running on local URL: http://127.0.0.1:7864\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"data": {
|
| 44 |
+
"text/html": [
|
| 45 |
+
"<div><iframe src=\"http://127.0.0.1:7864/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 46 |
+
],
|
| 47 |
+
"text/plain": [
|
| 48 |
+
"<IPython.core.display.HTML object>"
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"output_type": "display_data"
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"source": [
|
| 56 |
+
"#demo = gr.Interface(fn=greet, inputs=\"text\", outputs=\"text\")\n",
|
| 57 |
+
"\n",
|
| 58 |
+
"demo = gr.Interface(\n",
|
| 59 |
+
" fn=greet,\n",
|
| 60 |
+
" inputs=gr.Textbox(lines=2, placeholder=\"Name Here...\"),\n",
|
| 61 |
+
" outputs=\"text\",\n",
|
| 62 |
+
")\n",
|
| 63 |
+
"\n",
|
| 64 |
+
" \n",
|
| 65 |
+
"if __name__ == \"__main__\":\n",
|
| 66 |
+
" demo.launch()\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"\n"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"cell_type": "code",
|
| 74 |
+
"execution_count": null,
|
| 75 |
+
"id": "734a2cc4-a78a-40b5-a712-b3d2e314e1db",
|
| 76 |
+
"metadata": {},
|
| 77 |
+
"outputs": [],
|
| 78 |
+
"source": []
|
| 79 |
+
}
|
| 80 |
+
],
|
| 81 |
+
"metadata": {
|
| 82 |
+
"kernelspec": {
|
| 83 |
+
"display_name": "Python 3 (ipykernel)",
|
| 84 |
+
"language": "python",
|
| 85 |
+
"name": "python3"
|
| 86 |
+
},
|
| 87 |
+
"language_info": {
|
| 88 |
+
"codemirror_mode": {
|
| 89 |
+
"name": "ipython",
|
| 90 |
+
"version": 3
|
| 91 |
+
},
|
| 92 |
+
"file_extension": ".py",
|
| 93 |
+
"mimetype": "text/x-python",
|
| 94 |
+
"name": "python",
|
| 95 |
+
"nbconvert_exporter": "python",
|
| 96 |
+
"pygments_lexer": "ipython3",
|
| 97 |
+
"version": "3.9.18"
|
| 98 |
+
}
|
| 99 |
+
},
|
| 100 |
+
"nbformat": 4,
|
| 101 |
+
"nbformat_minor": 5
|
| 102 |
+
}
|