Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Import + Translate recipe images with OpenAI #3974

Merged

Conversation

michael-genson
Copy link
Collaborator

@michael-genson michael-genson commented Aug 2, 2024

What type of PR is this?

(REQUIRED)

  • feature

What this PR does / why we need it:

(REQUIRED)

This adds a new recipe creation method to create recipes from images using AI. Optionally, users may opt to translate the recipe into their own language as well.

Here's the new interface:
image
image

Copying the work from recipe timeline events, you can rotate/crop the image after uploading it:
image

It can take a while, so we have a loading text/animation:
image

And voilà, a handwritten recipe translated from German to English:
image

I don't speak German, so I hope it's accurate 😅 But it seems to check out (ingredient/step counts, similar words, etc.).

Which issue(s) this PR fixes:

(REQUIRED)

Closes #660
Closes #1588
Closes #3899
Kind of addresses #3011 (see special notes below)

Special notes for your reviewer:

(fill-in or delete this section)

The translate feature is super helpful even without the image processing. At some point I plan to have a more general "Import with AI" that can accept URLs, text, images, etc.

Testing

(fill-in or delete this section)

Tested with a ton of images of recipes from Google, as well as some cookbooks I have at home. Works great!

@lindell
Copy link
Contributor

lindell commented Aug 9, 2024

This is great! I've tested this on a few Swedish recipes and it generally works as expected.

I will add some examples of where I find things going wrong. Most might be what gpt4-o returned. But it might also be something we might improve upon with better prompting. Nothing critical, but some might be fixable.

Example one:

  1. I got a servings/total_yield of 4 port, ca 20 min. For some reason, it added the total time to it. Prompting looks reasonable, I think this is mostly an error from the model.
  2. 1. / 2. etc was included as a part of the recipe instructions. I see this is in the json schema. So I'm not sure there is anything to do about it?

The recipe:
example recipe parsed

@freakshock88
Copy link

This is a great idea indeed!
Just another idea.. could this not be easily adapted to parse unsupported (unscrapable) recipe websites?
A workaround is of course to make a screenshot.. but a url would be more user friendly.

@lindell
Copy link
Contributor

lindell commented Aug 9, 2024

This is a great idea indeed! Just another idea.. could this not be easily adapted to parse unsupported (unscrapable) recipe websites? A workaround is of course to make a screenshot.. but a url would be more user friendly.

@michael-genson has already added this! 😄
#3690

@freakshock88
Copy link

This is a great idea indeed! Just another idea.. could this not be easily adapted to parse unsupported (unscrapable) recipe websites? A workaround is of course to make a screenshot.. but a url would be more user friendly.

@michael-genson has already added this! 😄 #3690

Oh sorry about that, I tried it before I fixed my OpenAI setup I see now ;) It works indeed, awesome! Thanks for your response!

@lindell
Copy link
Contributor

lindell commented Aug 9, 2024

A note on the translation.

I use Mealie (and all other software) in English. But I and those I share the instance with have all my recipes in my first language (Swedish). To translate a recipe, I have to change the Mealie language to Swedish, to the importing, and then change the language back 😛

I will almost never use the translate feature, so it does not matter for me. But thought it was worth noting.

Co-authored-by: Johan Lindell <johan@lindell.me>
@michael-genson
Copy link
Collaborator Author

  1. / 2. etc was included as a part of the recipe instructions

Yeah I tried building that into the prompt:

Sometimes, but not always, recipes will include their number in front of the text, such as ... In the case where they are directly numbered ... you should not include the number in the text.

It just seems to ignore it sometimes ¯\_(ツ)_/¯

To translate a recipe, I have to change the Mealie language to Swedish, to the importing, and then change the language back

I figure this is an edge-case, but maybe we can build it into the UI somehow. Maybe in the next iteration

@williamkray
Copy link

wow this is rad, i have a ton of recipe cards we've saved from our old meal-box plans back in the day (blue apron, martha & marley spoon, etc) and would love to be able to import them just by running them through the scanner!

boc-the-git
boc-the-git previously approved these changes Aug 17, 2024
Copy link
Collaborator

@boc-the-git boc-the-git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
@boc-the-git boc-the-git enabled auto-merge (squash) August 17, 2024 22:06
@boc-the-git boc-the-git merged commit 8a15f40 into mealie-recipes:mealie-next Aug 17, 2024
11 checks passed
michael-genson added a commit to michael-genson/mealie that referenced this pull request Aug 20, 2024
Co-authored-by: Johan Lindell <johan@lindell.me>
Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
@felixschndr
Copy link
Contributor

This is really cool! Showed the feature to my girlfriend, has huge wife-approvalfactor!

@boc-the-git
Copy link
Collaborator

This is really cool! Showed the feature to my girlfriend, has huge wife-approvalfactor!

This feature got you married @felixschndr ?
@michael-genson works wonders!

@michael-genson michael-genson deleted the feat/openai-image-import branch August 23, 2024 02:45
@felixschndr
Copy link
Contributor

This feature got you married @felixschndr ?

(Sadly) not :D I didn't know wheter there was a word for girlfriend approval factor so I set wife in italic to mean girlfriend ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants