diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..06d1cd2d Binary files /dev/null and b/.DS_Store differ diff --git a/app/README.md b/app/README.md index 163d5ae3..f113a697 100644 --- a/app/README.md +++ b/app/README.md @@ -1,4 +1,4 @@ -# UofTHacks +# SnapToSavor Our ingredients to recipe app for UofTHacks 11! ## Instructions diff --git a/app/__pycache__/food_api.cpython-311.pyc b/app/__pycache__/food_api.cpython-311.pyc new file mode 100644 index 00000000..c60f44df Binary files /dev/null and b/app/__pycache__/food_api.cpython-311.pyc differ diff --git a/app/backend/__pycache__/formatted_recipes.cpython-310.pyc b/app/backend/__pycache__/formatted_recipes.cpython-310.pyc new file mode 100644 index 00000000..2f4d4bb8 Binary files /dev/null and b/app/backend/__pycache__/formatted_recipes.cpython-310.pyc differ diff --git a/app/backend/sql_bcknd/RecipePublic.db b/app/backend/sql_bcknd/RecipePublic.db index 7b096d4c..ebbb73b5 100644 Binary files a/app/backend/sql_bcknd/RecipePublic.db and b/app/backend/sql_bcknd/RecipePublic.db differ diff --git a/app/backend/sql_func.py b/app/backend/sql_func.py index 6304196a..d9a0f64b 100644 --- a/app/backend/sql_func.py +++ b/app/backend/sql_func.py @@ -43,30 +43,25 @@ def add_user(db, cursor, FirstName, LastName): cursor.execute('INSERT INTO UserPublic (UserID, FirstName, LastName, DateJoined)VALUES ("' + UserID +'","'+ FirstName +'","'+ LastName +'",'+ str(dt_now) + ')') db.commit() -def add_ingredient(db, cursor, IngredientName, Description = None, Sugar = None, Sodium = None, Fats = None, - Protien = None, A = None, B = None, C = None, D = None, Fiber = None, Calories = None): +##def add_ingredient(db, cursor, IngredientName, IngredientID, Description = None, Sugar = None, Sodium = None, Fats = None, + ##Protien = None, A = None, B = None, C = None, D = None, Fiber = None, Calories = None): +def add_ingredient(db, cursor, Ingredient): + db.commit() ing_ids = get_ing_ids(db, cursor) + #print(ing_ids) cursor.row_factory = None - IngredientID = 'MGJ83KT' - while IngredientID in ing_ids: - IngredientID = ''.join(random.choice('0123456789ABCDEF') for i in range(7)) - - args = locals() - args.pop("db") - args.pop("cursor") - args["IngredientID"] = IngredientID + if Ingredient["IngredientID"] not in ing_ids: + insert_query = '''INSERT INTO Ingredients (IngredientID, IngredientName) + VALUES ("{IngredientID}", "{IngredientName}") + '''.format(**Ingredient) - insert_query = '''INSERT INTO Ingredients (IngredientID, IngredientName, Description, Sugar_g, Sodium_mg, Fats_g, Protien_g, Vitamin_A_mcg, Vitamin_B_mcg, Vitamin_C_mcg, Vitamin_D_mcg, Fiber_g, Calories) - VALUES ("{IngredientID}", "{IngredientName}", "{Description}", "{Sugar}", "{Sodium}", "{Fats}", "{Protien}", "{A}", "{B}", "{C}", "{D}", "{Fiber}", "{Calories}") - '''.format(**args) + cursor.execute(insert_query) + db.commit() - cursor.execute(insert_query) - db.commit() -""" -def add_recipe(db, cursor, RecipeName, ): +def add_recipe(db, cursor, Recipe): recipe_ids = get_rec_ids(db, cursor) cursor.row_factory = None @@ -74,16 +69,104 @@ def add_recipe(db, cursor, RecipeName, ): RecipeID = 'ZKD3VY' while RecipeID in recipe_ids: RecipeID = ''.join(random.choice('0123456789ABCDEF') for i in range(6)) -""" + + user_ids = get_user_ids(db, cursor) + cursor.row_factory = None + UserID = random.choice(user_ids) ## DEV + + dt_now = datetime.datetime.now() + dt_now = int(dt_now.strftime('%Y%m%d')) + + Recipe["RecipeID"] = RecipeID + Recipe["UserID"] = UserID + Recipe["DatePosted"] = dt_now + #Recipe["RecipeThumbnailLink"] = Recipe["RecipeThumbnailLink"].replace('/','?') + #Recipe["RecipeThumbnailLink"] = Recipe["RecipeThumbnailLink"].replace(':','-') + Recipe["RecipeThumbnailLink"] = Recipe["RecipeThumbnailLink"].replace(' ','') + Recipe["Description"] = "" + + insert_recipe = '''INSERT INTO Recipes (RecipeID, RecipeName, UserID, Description, RecipeThumbnailLink, DatePosted) + VALUES ( + "{RecipeID}", + "{RecipeName}", + "{UserID}", + "{Description}", + "{RecipeThumbnailLink}", + "{DatePosted}" + ) + '''.format(**Recipe) + + cursor.execute(insert_recipe) + for RecipeIngredient in Recipe["RecipeIngredients"]: + RecipeIngredient["RecipeID"] = RecipeID + + insert_recipe_ingredient = '''INSERT INTO RecipeIngredients_STG (RecipeID, IngredientID, Quantity, QuantityUnit) + VALUES ( + "{RecipeID}", + "{IngredientID}", + {Quantity}, + "{QuantityUnit}" + ) + '''.format(**RecipeIngredient) + + #print(insert_recipe_ingredient) + + cursor.execute(insert_recipe_ingredient) + db.commit() + + add_ingredient(db,cursor,RecipeIngredient) + +def get_recipe(db, cursor, RecipeID): + select_query = '''SELECT * FROM ( + SELECT + Recipes.*, + group_concat(Quantity || " " || QuantityUnit || " of " || A.IngredientName, ", ") AS "IngredientsList" + + FROM Recipes + + JOIN RecipeIngredients_STG ON RecipeIngredients_STG.RecipeID = Recipes.RecipeID + JOIN ( + SELECT DISTINCT IngredientID, IngredientName FROM Ingredients + ) AS A ON RecipeIngredients_STG.IngredientID = A.IngredientID + + GROUP BY Recipes.RecipeID + ) AS A + WHERE A.RecipeID = "{}" + '''.format(RecipeID) + + cursor.execute(select_query) + return cursor.fetchall() + +def get_recipe_by_ingredient(IngredientList): + IngredientsString = ', '.join(f'"{i}"' for i in IngredientList) + + select_query = '''SELECT DISTINCT RecipeID + FROM ( + SELECT RecipeIngredients_STG.RecipeID, RecipeIngredients_STG.IngredientID, Ingredients.IngredientName FROM RecipeIngredients_STG + JOIN Ingredients ON Ingredients.IngredientID = RecipeIngredients_STG.IngredientID + ) AS A + WHERE A.IngredientName IN ({}) + '''.format(IngredientsString) + + cursor.row_factory = lambda cursor, row: row[0] + cursor.execute(select_query) + return cursor.fetchall() + ## ------------- Testing Workspace ---------------- -##db, cursor = sql_connect('RecipePublic.db') +#db, cursor = sql_connect('RecipePublic.db') +#print(get_recipe(db, cursor, "015284")) +#print(get_recipe_by_ingredient(["butter","cream cheese"])) ##add_user(db, cursor, "Jane", "Doe") ##add_ingredient(db, cursor, IngredientName = "Banana", Description = "An elongated, edible fruit, botanically a berry") +##recipes = get_recipes() +##for recipe in recipes: + ##add_recipe(db, cursor, recipe) + ##with open('sql_bcknd/test.sql', 'r') as sql_file: ##sql_script = sql_file.read() diff --git a/app/extra/ex.json b/app/extra/ex.json index 2ffcb832..f56fea85 100644 --- a/app/extra/ex.json +++ b/app/extra/ex.json @@ -2,7 +2,7 @@ "RecipeID": 640266, "RecipeName": "Crab and Shrimp Burgers With Garlic Grits Fries", "Description": "", - "RecipeThumbnailLink": "https: //spoonacular.com/recipeImages/640266-556x370.jpg", + "RecipeThumbnailLink": "https://spoonacular.com/recipeImages/640266-556x370.jpg", "DatePosted": "", "RecipeIngredients": [ { diff --git a/app/extra/src/confirm_ing/__pycache__/confirm_ing.cpython-311.pyc b/app/extra/src/confirm_ing/__pycache__/confirm_ing.cpython-311.pyc deleted file mode 100644 index 99e77edb..00000000 Binary files a/app/extra/src/confirm_ing/__pycache__/confirm_ing.cpython-311.pyc and /dev/null differ diff --git a/app/extra/src/img/MBTI.png b/app/extra/src/img/MBTI.png deleted file mode 100644 index 58082d62..00000000 Binary files a/app/extra/src/img/MBTI.png and /dev/null differ diff --git a/app/food_api.py b/app/food_api.py index ed96011e..83e54b7f 100644 --- a/app/food_api.py +++ b/app/food_api.py @@ -1,11 +1,27 @@ import requests +from PIL import Image +import os +from pages.landing_page import * + +def compress_img(input_img_path, output_img_path, quality=50): + try: + with Image.open(input_img_path) as img: + img.save(output_img_path, quality=quality) + except Exception as e: + print(f"Error: {e}") #saves a list of the different items! # img format should be the file path of the image. Ex: /User def get_ingredients(img): - api_user_token = 'fb5a4c7df78e749b63d71a34cfd375c689a8e441' + api_user_token = '016da25e7e5a4e2f2b8bff3b0664c6612665ef09' headers = {'Authorization': 'Bearer ' + api_user_token} + # Compression + input_image_path = img + output_image_path = "./img/compressed_image.jpg" + compress_img(input_image_path, output_image_path) + img = output_image_path + # Single/Several Dishes Detection url = 'https://api.logmeal.es/v2/image/segmentation/complete' resp = requests.post(url,files={'image': open(img, 'rb')},headers=headers) @@ -20,5 +36,5 @@ def get_ingredients(img): # Test of the call -#food_name_test = get_ingredients('/Users/marilynzhang/Desktop/food_test_2.jpg') -#print(food_name_test) \ No newline at end of file +# food_name_test = get_ingredients(selected_files) +# print(food_name_test) diff --git a/app/img/compressed_image.jpg b/app/img/compressed_image.jpg new file mode 100644 index 00000000..45ea9b07 Binary files /dev/null and b/app/img/compressed_image.jpg differ diff --git a/app/main.py b/app/main.py index 9be44093..ee877293 100644 --- a/app/main.py +++ b/app/main.py @@ -4,6 +4,7 @@ from pages.found_recipes_page import * from pages.root_page import * from pages.confirm_ingredients_page import * +from food_api import * pages = { "/": root_page, @@ -18,6 +19,31 @@ } if __name__ == "__main__": + Gui(pages=pages).run(debug=True, use_reloader=True, port=8080, stylekit=stylekit, dark_mode=False) + +from taipy import Gui + +from pages.landing_page import * +from pages.found_recipes_page import * +from pages.root_page import * +from pages.confirm_ingredients_page import * + +pages = { + "/": root_page, + "ingredients": landing_page, + "confirm": confirm_ingredients_page, + "recipes": found_recipes_page +} + +stylekit = { + "color_primary": "#F87F7F", + "color_secondary": "#C0FFE", +} + +if __name__ == "__main__": + Gui(pages=pages).run(debug=True, use_reloader=True, port=8081, stylekit=stylekit, dark_mode=False) + + diff --git a/app/pages/confirm_ingredients_page.py b/app/pages/confirm_ingredients_page.py index 879fc5de..a2b10bd5 100644 --- a/app/pages/confirm_ingredients_page.py +++ b/app/pages/confirm_ingredients_page.py @@ -1,25 +1,35 @@ from taipy.gui import navigate -import os +from .landing_page import * +from food_api import * # Bindings -here = os.path.dirname(os.path.abspath(__file__)) -image = os.path.join(here, "./img/image-missing.svg") # default image without any user input -num_ingred = 0 +# here = os.path.dirname(os.path.abspath(__file__)) +# image = os.path.join(here, "./img/image-missing.svg") # default image without any user input +selected_files = None +ingredients = [] +num_ingred = 1 confirm_ingredients_page=""" -<|layout|columns=2 2| +<|layout|columns=2 3| <|card card-bg| -<|{image}|image|label="Uploaded Fridge Image"|> +
+<|{selected_files}|image|> +
|> <|card card-bg| -<|Confirm {num_ingred} ingredient(s):|>\n +<|Confirmed {num_ingred} ingredient(s):|>\n +<|{ingredients[0]}|> |> -<|Confirm|button|on_action=confirmed_ingred|> +<|Confirm|button|class_name=success|on_action=confirmed_ingred|> +<|Delete|button|class_name=error|on_action=delete_ingred|> |> """ -def confirmed_ingred(state): - print(image) - # navigate(state, "recipes") +def update_num_ingred(state): + num_ingred = num_ingred + 1 +def confirmed_ingred(state): + navigate(state, "recipes") +def delete_ingred(state): + navigate(state, to="ingredients") diff --git a/app/pages/found_recipes_page.py b/app/pages/found_recipes_page.py index f94fbb92..ce976dae 100644 --- a/app/pages/found_recipes_page.py +++ b/app/pages/found_recipes_page.py @@ -1,3 +1,34 @@ found_recipes_page = """ -### Hello. You found recipes +<|layout|columns=1 3| +<|card card-bg| +## Ingredients +<|card card-bg| {.red} +BANANA\n +BANANA BABY\n +BANANA +|> +|> +<|card card-bg| +## Recipes + +<|layout|columns=1 1 1| +<|card card-bg| +<|app/pages/img/banana.jpg|image|> +|> +<|card card-bg| +<|app/pages/img/banana-baby-producto-caribbean-exotics.png|image|> +|> +<|card card-bg| +<|app/pages/img/banana.jpg|image|> +|> +|> +|> +|> """ + + +# recipe = call database +# recipes = len[recipe] + +# def nonempty(): +# return recipes != 0 \ No newline at end of file diff --git a/app/pages/img/MBTI.png b/app/pages/img/MBTI.png deleted file mode 100644 index 58082d62..00000000 Binary files a/app/pages/img/MBTI.png and /dev/null differ diff --git a/app/pages/img/banana-baby-producto-caribbean-exotics.png b/app/pages/img/banana-baby-producto-caribbean-exotics.png new file mode 100644 index 00000000..9f575b34 Binary files /dev/null and b/app/pages/img/banana-baby-producto-caribbean-exotics.png differ diff --git a/app/pages/img/banana.jpg b/app/pages/img/banana.jpg new file mode 100644 index 00000000..370a20c2 Binary files /dev/null and b/app/pages/img/banana.jpg differ diff --git a/app/pages/img/edit-button.svg b/app/pages/img/edit-button.svg new file mode 100644 index 00000000..36fc5fbd --- /dev/null +++ b/app/pages/img/edit-button.svg @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/pages/img/image-missing.svg b/app/pages/img/image-missing.svg deleted file mode 100644 index 2e42376c..00000000 --- a/app/pages/img/image-missing.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/pages/img/missing_img.jpg b/app/pages/img/missing_img.jpg new file mode 100644 index 00000000..c3c0fae4 Binary files /dev/null and b/app/pages/img/missing_img.jpg differ diff --git a/app/pages/img/trash.png b/app/pages/img/trash.png new file mode 100644 index 00000000..2c2c8bf9 Binary files /dev/null and b/app/pages/img/trash.png differ diff --git a/app/pages/landing_page.py b/app/pages/landing_page.py index 5ed83e3e..aaa11b0c 100644 --- a/app/pages/landing_page.py +++ b/app/pages/landing_page.py @@ -1,16 +1,18 @@ from taipy.gui import navigate +from food_api import get_ingredients # Bindings selected_files = None - value = "Search for recipe..." landing_page=""" <|{selected_files}|file_selector|label=Upload File|on_action=uploaded_files|extensions=.jpg,.jpeg,.png|drop_message=Drop Message|> -#Search for recipe: +## Search for recipe <|{value}|input|><|find|button|on_action=uploaded_files|> """ def uploaded_files(state): + state.ingredients = get_ingredients(state.selected_files) + state.num_ingred = len(state.ingredients) navigate(state, to="confirm") diff --git a/app/pages/root_page.py b/app/pages/root_page.py index 948bfbc8..ba6c8fd5 100644 --- a/app/pages/root_page.py +++ b/app/pages/root_page.py @@ -1,5 +1,5 @@ root_page = """ <|navbar|> -# Ingredient to Recipe App +# SnaptoSavor """ \ No newline at end of file