diff --git a/examples/recipegenerator/app.py b/examples/recipegenerator/app.py index db75c4aa..12225629 100644 --- a/examples/recipegenerator/app.py +++ b/examples/recipegenerator/app.py @@ -18,27 +18,34 @@ def index(): @app.route('/upload', methods=['POST']) def upload_file(): - if 'file' not in request.files: + if 'images' not in request.files: return jsonify({'error': 'No file part'}), 400 - file = request.files['file'] - if file.filename == '': + + files = request.files.getlist('images') + + if not files or files[0].filename == '': return jsonify({'error': 'No selected file'}), 400 - if file: - filename = os.path.join(app.config['UPLOAD_FOLDER'], GROCERY_PHOTO_FILE_NAME) - file.save(filename) - try: - # Execute the script to generate the recipe - subprocess.Popen(f"gptscript {SCRIPT_PATH}", shell=True, stdout=subprocess.PIPE, cwd=base_dir).stdout.read() - - # Read recipe.md file - recipe_file_path = os.path.join(app.config['UPLOAD_FOLDER'], RECIPE_FILE_NAME) - with open(recipe_file_path, 'r') as recipe_file: - recipe_content = recipe_file.read() - - # Return recipe content - return jsonify({'recipe': recipe_content}) - except Exception as e: - return jsonify({'error': str(e)}), 500 + + # Initialize a counter for file naming + file_counter = 1 + for file in files: + if file: + # Format the filename as "GroceryX.png" + filename = f"grocery{file_counter}.png" + save_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) + file.save(save_path) + file_counter += 1 # Increment the counter for the next file + + try: + # Calling the recipegenerator.gpt script + subprocess.Popen(f"gptscript {SCRIPT_PATH}", shell=True, stdout=subprocess.PIPE).stdout.read() + recipe_file_path = os.path.join(app.config['UPLOAD_FOLDER'], RECIPE_FILE_NAME) + with open(recipe_file_path, 'r') as recipe_file: + recipe_content = recipe_file.read() + # Return the recipe content + return jsonify({'recipe': recipe_content}) + except Exception as e: + return jsonify({'error': str(e)}), 500 if __name__ == '__main__': app.run(debug=False) diff --git a/examples/recipegenerator/recipegenerator.gpt b/examples/recipegenerator/recipegenerator.gpt index 5d8d5823..184f1101 100755 --- a/examples/recipegenerator/recipegenerator.gpt +++ b/examples/recipegenerator/recipegenerator.gpt @@ -2,8 +2,9 @@ tools: sys.find, sys.read, sys.write, recipegenerator, tool.gpt Perform the following steps in order: -1. Give me a list of 5 to 10 ingredients from the picture grocery.png located in the current directory and put those extracted ingredients into a list. -2. Based on these ingredients list, suggest me one recipe that is quick to cook and create a new recipe.md file with the recipe +1. Give me a list of ingredients from the pictures named with grocery in their name located in the current directory and put those extracted ingredients into a list. +2. For each picture analyzed in the previous step, write the ingredients identified into one file name ingredients.md. +3. Based on these ingredients list, suggest me one recipe that is quick to cook and create a new recipe.md file with the recipe --- diff --git a/examples/recipegenerator/templates/index.html b/examples/recipegenerator/templates/index.html index 62a80ebc..5efdb38b 100644 --- a/examples/recipegenerator/templates/index.html +++ b/examples/recipegenerator/templates/index.html @@ -3,7 +3,7 @@ - Recipe Generator + RecipAI - Recipe Generator @@ -26,7 +26,7 @@
-

Recipe Generator

-
-

Don't know what to do with what's in your shopping cart? Well, click a picture and upload the image to Recipe Generator that will give you interesting ideas of what you can cook from those ingredients! This is built using GPTScript.

-
+

RecipAI - Recipe Generator

+

Don't know what to do with what's in your shopping cart? Well, click a picture and upload the image to Recipe Generator that will give you interesting ideas of what you can cook from those ingredients! This is built using GPTScript.

-
+
- - -
+ + +
+
- + + +