File size: 2,289 Bytes
32ed852
 
542a039
 
68331a9
 
542a039
32ed852
 
 
 
 
 
1ba9158
 
 
 
32ed852
68331a9
 
 
1ba9158
68331a9
 
1ba9158
 
 
 
 
 
 
68331a9
 
 
 
1ba9158
db088a7
 
1ba9158
 
db088a7
542a039
 
1ba9158
542a039
 
 
1ba9158
 
 
 
 
 
542a039
32ed852
542a039
 
1ba9158
 
542a039
 
 
 
1ba9158
 
542a039
 
1ba9158
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from transformers import pipeline
from PIL import Image
import gradio as gr
import os
import requests
import json

model_name = "larimei/food-classification-ai"

classifier = pipeline("image-classification", model=model_name)

def predict_image(image):
    predictions = classifier(image)
    meal_name = predictions[0]['label']
    recipe_text = getRecipe(meal_name)
    meal_info = f"This is {meal_name.replace('_', ' ')}."
    return meal_info, recipe_text

def getRecipe(meal):
    app_id = "24bf0913"
    app_key = "03c60f26520f9d25b0d0617e50993aaa"
    field = ["uri", "label", "image", "ingredientLines", "source", "url"]
    url = "https://api.edamam.com/api/recipes/v2"

    querystring = {
        "type": "public",
        "q": meal.replace("_", " "),
        "app_id": app_id,
        "app_key": app_key,
        "field": field
    }

    response = requests.get(url, params=querystring)
    json_object = response.json()

    returnString = "It is made out of the following ingredients: \n\n"
    for line in json_object["hits"][0]["recipe"]["ingredientLines"]:
        returnString += line + "\n"
    returnString += "\n You can make " + json_object["hits"][0]["recipe"]["label"] + " yourself by following the steps of this instruction: " + json_object["hits"][0]["recipe"]["url"]

    return returnString

title = "Recipifier"
description = "Discover the world of recipes effortlessly with Recipifier, using advanced AI trained on the extensive Food-101 dataset. Simply upload a photo of any dish, and our application identifies it accurately, providing detailed recipes and cooking instructions sourced from a vast collection. Perfect for food enthusiasts and home chefs alike, Recipifier makes exploring new culinary creations intuitive and inspiring. Start transforming everyday ingredients into extraordinary meals today!"

example_list = [["examples/" + example] for example in os.listdir("examples")]

css = """
#component-13 {
    display: none;
}
"""

demo = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="pil"),
    outputs=[
        gr.Textbox(label="Meal", elem_id="meal"),
        gr.Textbox(label="Recipe") 
    ],
    examples=example_list,
    title=title,
    description=description,
    css=css,
    flagging_options=None  
)

demo.launch()