Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- llm_api/connect.py +15 -0
- meal_planner_api/config.py +2 -0
- meal_planner_api/create_meal_plan.py +15 -0
- meal_planner_api/utils.py +7 -0
llm_api/connect.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from meal_planner_api import utils
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
from meal_planner_api import config
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def generate_content(text: str):
|
| 7 |
+
model = connect()
|
| 8 |
+
response = model.generate_content(text)
|
| 9 |
+
return response.text
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def connect():
|
| 13 |
+
genai.configure(api_key=config.API_KEY)
|
| 14 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 15 |
+
return model
|
meal_planner_api/config.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
API_KEY = os.environ.get("GENAI_API_KEY")
|
meal_planner_api/create_meal_plan.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm_api import connect
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def generate(age, gender,current_weight, desired_weight, goal, restrictions, preferences):
|
| 5 |
+
vegetarian_text = "vegetarian" if vegetarian == "Yes" else "non-vegetarian"
|
| 6 |
+
prompt = (
|
| 7 |
+
f"Create a personalized one-week meal plan for someone whose goal is to {goal}, "
|
| 8 |
+
f"with an activity level of '{activity_level}', targeting {daily_calories} calories daily. "
|
| 9 |
+
f"The person prefers {vegetarian_text} meals and follows a '{meal_preference}' diet with {meal_count} meals per day. "
|
| 10 |
+
f"Each day should include breakfast, lunch, dinner, and snacks if applicable."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
meal_plan = connect.generate_content(prompt)
|
| 14 |
+
|
| 15 |
+
return meal_plan
|
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))
|