brilianputraa commited on
Commit
111d795
1 Parent(s): 8d262ea

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +74 -6
src/app.py CHANGED
@@ -21,6 +21,11 @@ class Kokiku:
21
 
22
  self.servings = ["1 person", "2 people", "3 people", "4 people", "5 people", "6 people", "7 people", "8 people", "9 people", "10 people"]
23
  self.cooking_tools = ["Pan", "Oven", "Air Fryer", "Microwave", "Griller", "Steamer", "Rice Cooker", "Blender"]
 
 
 
 
 
24
  self.ingredients = []
25
  self.include_shopping_list = True
26
 
@@ -106,7 +111,6 @@ class Kokiku:
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
@@ -160,9 +164,62 @@ class Kokiku:
160
  except AssertionError:
161
  return "","**Please complete the information first!**"
162
 
163
- def prompt_order_recommendation(self):
164
- return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  def generate_recipe(self, cuisine, cooking_skill, cooking_time, eating_time, servings, health_condition, intolerances, include_facts):
167
  interface = gr.Interface(self.prompt_additional, css="footer{display:none !important}", show_label=True, theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), inputs=[gr.Textbox(input="text", label="Ingredients", info="What's inside your fridge?", placeholder="Chicken, Goguma, Chili etc"), gr.Dropdown(cuisine, value=cuisine[0], label="Cuisine", info="What Cuisine that you crave now?"), gr.Radio(cooking_skill, value=cooking_skill[0], label="Cooking Skill", info="What is your cooking skill?"),
168
  gr.Radio(cooking_time, value=cooking_time[0], label="Cooking Time", info="How much time do you have to cook?"), gr.Radio(eating_time, value=eating_time[0], label="Eating Time", info="When do you want to eat?"), gr.Dropdown(servings, value=servings[0], label="Servings", info="How many people will eat?"),
@@ -178,16 +235,27 @@ class Kokiku:
178
  gr.Checkbox(include_facts, label="Include Nutrition Facts?")], outputs=[gr.Radio(label="Kokiku's Meal Plan", placeholder="Complete the information to see our meal plans recommendations", default="Complete the information to see our meal plans recommendations", readonly=True, info="Our meal plans recommendation will be shown here!"), gr.Markdown()])
179
  return interface
180
 
181
- def generate_order_recommendaton(self):
182
- interface = gr.Interface(self.prompt_order_recommendation, css="footer{display:none !important}", show_label=True, theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), inputs=[gr.Textbox(input="text")], outputs=[gr.Markdown()])
 
 
183
  return interface
 
 
 
 
 
 
 
 
 
184
 
185
 
186
  def main():
187
  kokiku = Kokiku()
188
  app_recipe = kokiku.generate_recipe(kokiku.cuisine, kokiku.cooking_skill, kokiku.cooking_time, kokiku.eating_time, kokiku.servings, kokiku.health_condition, kokiku.intolerances, kokiku.include_facts)
189
  app_plan = kokiku.generate_meal_plan(kokiku.plan_duration, kokiku.meals_per_day, kokiku.cuisine, kokiku.cooking_skill, kokiku.cooking_time, kokiku.intolerances, kokiku.servings, kokiku.include_shopping_list, kokiku.include_facts)
190
- app_order = kokiku.generate_order_recommendaton()
191
  app_entire = gr.TabbedInterface([app_recipe, app_plan, app_order], tab_names=["Recipe Maker", "Meal Planner", "What to Order"], title="Kokiku", theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), css="footer{display:none !important}")
192
  app_entire.launch(favicon_path="/assets/chef.ico", debug=False)
193
 
 
21
 
22
  self.servings = ["1 person", "2 people", "3 people", "4 people", "5 people", "6 people", "7 people", "8 people", "9 people", "10 people"]
23
  self.cooking_tools = ["Pan", "Oven", "Air Fryer", "Microwave", "Griller", "Steamer", "Rice Cooker", "Blender"]
24
+ self.countries = ["South Korea", "United States", "Indonesia", "United Kingdom", "Singapore", "Japan", "Australia"]
25
+ self.merchant = ["McDonalds", "Subway", "Starbucks", "KFC", "Pizza Hut", "Burger King", "Dunkin Donuts", "Domino's Pizza", "Pizza Hut", "KFC", "Krispy Kreme", "Papa's John", "Domino Pizza", "Taco Bell"]
26
+ self.activity_level = ["Sedentary", "Lightly Active", "Moderately Active", "Very Active", "Extra Active"]
27
+ self.age = 1
28
+
29
  self.ingredients = []
30
  self.include_shopping_list = True
31
 
 
111
  return "","**Please complete the information first!**"
112
 
113
  def prompt_meal_plan(self, ingredients, plan_duration, meals_per_day, cuisine, cooking_skill, cooking_time, intolerances, include_facts, shopping_list, servings):
 
114
  # Check if the input is complete
115
  try:
116
  assert ingredients != None
 
164
  except AssertionError:
165
  return "","**Please complete the information first!**"
166
 
167
+ def prompt_order_recommendation(self, eating_time, merchant, countries, activity_level, ingredients, age, intolerances):
168
+ # Check if the input is complete
169
+ try:
170
+ assert ingredients != None
171
+ assert merchant != None
172
+ assert countries != None
173
+ assert activity_level != None
174
+ assert intolerances != None
175
+ assert age != None
176
+ assert eating_time != None
177
+
178
+ # Preprocess the input
179
+ eating_time = eating_time.lower()
180
+ merchant = merchant.lower()
181
+ countries = countries.lower()
182
+ activity_level = activity_level.lower()
183
+ intolerances = intolerances.lower()
184
+
185
+ self._order_recommendation_intolerances_prompt = f"Exclude {intolerances}. "
186
+
187
+ if ingredients != "":
188
+ punct = "," + ";"
189
+ self.ingredients = "".join(ch for ch in ingredients if ch not in punct)
190
+ assert self.ingredients != [], "Please input your ingredients first"
191
+ self.ingredients = self.ingredients.lower()
192
+ self._order_recommendation_prompt = f"Suggest me what to order for {eating_time} at {merchant} {countries}, which contain {ingredients} "
193
+ else:
194
+ return "","**Please input the ingredients first!**"
195
+
196
+ if age.isnumeric():
197
+ age = int(age)
198
+ if self.is_integer(age) and age > 0 and age < 105:
199
+ self._order_recommendation_prompt += f"and enough nutrient for age {age} with {activity_level} activity level. "
200
+ else:
201
+ return "","**Please input the age first within the range (1 <= age <= 105 years)!**"
202
+ else:
203
+ return "","**Please input the age first with the correct value!**"
204
 
205
+ # Initialize the final prompt
206
+ self._final_prompt = self._order_recommendation_prompt
207
+
208
+ if intolerances != "none":
209
+ self._meal_planner_final_prompt += self._meal_planner_intolerances_prompt
210
+
211
+ self._final_prompt += " Give the condensed yet detailed answer"
212
+
213
+ # response = ai.ChatCompletion.create(
214
+ # model="gpt-3.5-turbo-0613",
215
+ # temperature=0.9,
216
+ # messages = [{"role": "user", "content": "What's the weather like in Boston?"}]
217
+ # )
218
+ # print(response.json())
219
+ return "", self._final_prompt
220
+ except AssertionError:
221
+ return "","**Please complete the information first!**"
222
+
223
  def generate_recipe(self, cuisine, cooking_skill, cooking_time, eating_time, servings, health_condition, intolerances, include_facts):
224
  interface = gr.Interface(self.prompt_additional, css="footer{display:none !important}", show_label=True, theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), inputs=[gr.Textbox(input="text", label="Ingredients", info="What's inside your fridge?", placeholder="Chicken, Goguma, Chili etc"), gr.Dropdown(cuisine, value=cuisine[0], label="Cuisine", info="What Cuisine that you crave now?"), gr.Radio(cooking_skill, value=cooking_skill[0], label="Cooking Skill", info="What is your cooking skill?"),
225
  gr.Radio(cooking_time, value=cooking_time[0], label="Cooking Time", info="How much time do you have to cook?"), gr.Radio(eating_time, value=eating_time[0], label="Eating Time", info="When do you want to eat?"), gr.Dropdown(servings, value=servings[0], label="Servings", info="How many people will eat?"),
 
235
  gr.Checkbox(include_facts, label="Include Nutrition Facts?")], outputs=[gr.Radio(label="Kokiku's Meal Plan", placeholder="Complete the information to see our meal plans recommendations", default="Complete the information to see our meal plans recommendations", readonly=True, info="Our meal plans recommendation will be shown here!"), gr.Markdown()])
236
  return interface
237
 
238
+ def generate_order_recommendaton(self, eating_time, merchant, countries, activity_level, intolerances):
239
+ interface = gr.Interface(self.prompt_order_recommendation, css="footer{display:none !important}", show_label=True, theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), inputs=[gr.Radio(eating_time, value=eating_time[0], label="Eating Time", info="When do you want to eat?"), gr.Dropdown(merchant, value=merchant[0], label="Merchant", info="Where are you going to eat?"), gr.Dropdown(countries, value=countries[0], label="Country", info="Which country?"),
240
+ gr.Dropdown(activity_level, value=activity_level[0], label="Activty Level", info="How active are you?"), gr.Textbox(input="text", label="Ingredients", info="What ingredients to include in your food?", placeholder="Beef, Celery, Meatballs"), gr.Textbox(input="text", label="Age", info="How old are you?", placeholder="20 (numbers only)"), gr.Dropdown(intolerances, value=intolerances[0], label="Intolerances", info="Is there any intolerances?")],
241
+ outputs=[gr.Radio(label="Kokiku's order suggestion", placeholder="Complete the information to see our order suggestions", default="Complete the information to see our order suggestions", readonly=True, info="Our food order recommendations will be shown here!"), gr.Markdown()])
242
  return interface
243
+
244
+ @staticmethod
245
+ def is_integer(n):
246
+ try:
247
+ float(n)
248
+ except ValueError:
249
+ return False
250
+ else:
251
+ return float(n).is_integer()
252
 
253
 
254
  def main():
255
  kokiku = Kokiku()
256
  app_recipe = kokiku.generate_recipe(kokiku.cuisine, kokiku.cooking_skill, kokiku.cooking_time, kokiku.eating_time, kokiku.servings, kokiku.health_condition, kokiku.intolerances, kokiku.include_facts)
257
  app_plan = kokiku.generate_meal_plan(kokiku.plan_duration, kokiku.meals_per_day, kokiku.cuisine, kokiku.cooking_skill, kokiku.cooking_time, kokiku.intolerances, kokiku.servings, kokiku.include_shopping_list, kokiku.include_facts)
258
+ app_order = kokiku.generate_order_recommendaton(kokiku.eating_time, kokiku.merchant, kokiku.countries, kokiku.activity_level, kokiku.intolerances)
259
  app_entire = gr.TabbedInterface([app_recipe, app_plan, app_order], tab_names=["Recipe Maker", "Meal Planner", "What to Order"], title="Kokiku", theme=gr.themes.Soft(primary_hue="orange", secondary_hue="orange"), css="footer{display:none !important}")
260
  app_entire.launch(favicon_path="/assets/chef.ico", debug=False)
261