Spaces:
Sleeping
Sleeping
Commit
·
8d262ea
1
Parent(s):
f6e0ffc
Update src/app.py
Browse files- src/app.py +71 -2
src/app.py
CHANGED
@@ -23,11 +23,29 @@ class Kokiku:
|
|
23 |
self.cooking_tools = ["Pan", "Oven", "Air Fryer", "Microwave", "Griller", "Steamer", "Rice Cooker", "Blender"]
|
24 |
self.ingredients = []
|
25 |
self.include_shopping_list = True
|
|
|
|
|
26 |
self._main_prompt = ""
|
27 |
self._health_condition_prompt = ""
|
28 |
self._intolerances_prompt = ""
|
29 |
self._include_facts_prompt = ""
|
30 |
self._final_prompt = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
self._openai_key = os.getenv("OPENAI_KEY")
|
32 |
# ai.api_key = self._openai_key
|
33 |
|
@@ -87,9 +105,60 @@ class Kokiku:
|
|
87 |
except AssertionError:
|
88 |
return "","**Please complete the information first!**"
|
89 |
|
90 |
-
def prompt_meal_plan(self, ingredients, plan_duration, meals_per_day, cuisine, cooking_skill, cooking_time, intolerances,
|
91 |
prompt = "Make 1 week meal plan (2 meals/day) consist of Korean and western food using chicken, which can be cooked with beginner skill during 30 minutes of cooking time. Exclude seafood and show the nutrition facts for one portion of each meal. Make a shopping list for 2 people according to it. Answer it directly"
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
def prompt_order_recommendation(self):
|
95 |
return
|
|
|
23 |
self.cooking_tools = ["Pan", "Oven", "Air Fryer", "Microwave", "Griller", "Steamer", "Rice Cooker", "Blender"]
|
24 |
self.ingredients = []
|
25 |
self.include_shopping_list = True
|
26 |
+
|
27 |
+
# Main Prompt
|
28 |
self._main_prompt = ""
|
29 |
self._health_condition_prompt = ""
|
30 |
self._intolerances_prompt = ""
|
31 |
self._include_facts_prompt = ""
|
32 |
self._final_prompt = ""
|
33 |
+
|
34 |
+
# Meal Planner Prompt
|
35 |
+
self._meal_planner_prompt = ""
|
36 |
+
self._meal_planner_intolerances_prompt = ""
|
37 |
+
self._meal_planner_include_facts_prompt = ""
|
38 |
+
self._meal_planner_shopping_list_prompt = ""
|
39 |
+
self._meal_planner_final_prompt = ""
|
40 |
+
|
41 |
+
# Order Recommendation Prompt
|
42 |
+
self._order_recommendation_prompt = ""
|
43 |
+
self._order_recommendation_health_condition_prompt = ""
|
44 |
+
self._order_recommendation_intolerances_prompt = ""
|
45 |
+
self._order_recommendation_include_facts_prompt = ""
|
46 |
+
self._order_recommendation_shopping_list_prompt = ""
|
47 |
+
self._order_recommendation_final_prompt = ""
|
48 |
+
|
49 |
self._openai_key = os.getenv("OPENAI_KEY")
|
50 |
# ai.api_key = self._openai_key
|
51 |
|
|
|
105 |
except AssertionError:
|
106 |
return "","**Please complete the information first!**"
|
107 |
|
108 |
+
def prompt_meal_plan(self, ingredients, plan_duration, meals_per_day, cuisine, cooking_skill, cooking_time, intolerances, include_facts, shopping_list, servings):
|
109 |
prompt = "Make 1 week meal plan (2 meals/day) consist of Korean and western food using chicken, which can be cooked with beginner skill during 30 minutes of cooking time. Exclude seafood and show the nutrition facts for one portion of each meal. Make a shopping list for 2 people according to it. Answer it directly"
|
110 |
+
# Check if the input is complete
|
111 |
+
try:
|
112 |
+
assert ingredients != None
|
113 |
+
assert cuisine != None
|
114 |
+
assert cooking_skill != None
|
115 |
+
assert cooking_time != None
|
116 |
+
assert servings != None
|
117 |
+
assert intolerances != None
|
118 |
+
|
119 |
+
# Preprocess the input
|
120 |
+
plan_duration = plan_duration.lower()
|
121 |
+
meals_per_day = meals_per_day.lower()
|
122 |
+
cuisine = cuisine.lower()
|
123 |
+
cooking_skill = cooking_skill.lower()
|
124 |
+
cooking_time = cooking_time.lower()
|
125 |
+
intolerances = intolerances.lower()
|
126 |
+
|
127 |
+
self._meal_planner_intolerances_prompt = f"Exclude {intolerances}. "
|
128 |
+
self._meal_planner_include_facts_prompt = "Provide the nutritions fact for recipe's one portion. "
|
129 |
+
self._meal_planner_shopping_list_prompt = f"Make a shopping list for {servings} according to it. "
|
130 |
+
|
131 |
+
|
132 |
+
if ingredients != "":
|
133 |
+
punct = "," + ";"
|
134 |
+
self.ingredients = "".join(ch for ch in ingredients if ch not in punct)
|
135 |
+
assert self.ingredients != [], "Please input your ingredients first"
|
136 |
+
self.ingredients = self.ingredients.lower()
|
137 |
+
self._meal_planner_prompt = f"Make {plan_duration} meal plan ({meals_per_day}/day) consist of {cuisine} food using {self.ingredients}, which can be cooked with {cooking_skill} skill during {cooking_time} of cooking time. "
|
138 |
+
else:
|
139 |
+
return "","**Please input the ingredients first!**"
|
140 |
+
|
141 |
+
# Initialize the final prompt
|
142 |
+
self._final_prompt = self._meal_planner_prompt
|
143 |
+
|
144 |
+
if intolerances != "none":
|
145 |
+
self._meal_planner_final_prompt += self._meal_planner_intolerances_prompt
|
146 |
+
if include_facts:
|
147 |
+
self._meal_planner_final_prompt += self._meal_planner_shopping_list_prompt
|
148 |
+
if shopping_list:
|
149 |
+
self._meal_planner_final_prompt += self._meal_planner_shopping_list_prompt
|
150 |
+
|
151 |
+
self._final_prompt += " Give the condensed yet detailed answer"
|
152 |
+
|
153 |
+
# response = ai.ChatCompletion.create(
|
154 |
+
# model="gpt-3.5-turbo-0613",
|
155 |
+
# temperature=0.9,
|
156 |
+
# messages = [{"role": "user", "content": "What's the weather like in Boston?"}]
|
157 |
+
# )
|
158 |
+
# print(response.json())
|
159 |
+
return "", self._final_prompt
|
160 |
+
except AssertionError:
|
161 |
+
return "","**Please complete the information first!**"
|
162 |
|
163 |
def prompt_order_recommendation(self):
|
164 |
return
|