Spaces:
Running
Running
update
Browse files
app.py
CHANGED
@@ -11,65 +11,58 @@ classifier = pipeline("image-classification", model=model_name)
|
|
11 |
|
12 |
def predict_image(image):
|
13 |
predictions = classifier(image)
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
def getRecipe(meal):
|
17 |
-
#meal = "hamburger"
|
18 |
app_id = "24bf0913"
|
19 |
app_key = "03c60f26520f9d25b0d0617e50993aaa"
|
20 |
-
|
21 |
-
field = ["uri","label","image","ingredientLines","source","url"]
|
22 |
url = "https://api.edamam.com/api/recipes/v2"
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
"app_key": app_key,
|
32 |
-
"field": field}
|
33 |
-
|
34 |
|
35 |
response = requests.get(url, params=querystring)
|
36 |
-
|
37 |
-
#print(response.content)
|
38 |
-
|
39 |
json_object = response.json()
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
print(json_formatted_str)
|
44 |
-
#print(json_object)
|
45 |
-
|
46 |
-
#whole response
|
47 |
-
#return json_object
|
48 |
-
|
49 |
-
#just one result
|
50 |
-
#return json_object["hits"][0]
|
51 |
-
|
52 |
-
returnString = "This is " + meal.replace("_"," ") + ". \n\n It is Made out of following ingredients: \n\n"
|
53 |
for line in json_object["hits"][0]["recipe"]["ingredientLines"]:
|
54 |
returnString += line + "\n"
|
55 |
-
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"]
|
56 |
-
|
57 |
return returnString
|
58 |
|
59 |
title = "Recipifier"
|
60 |
-
description = "
|
61 |
|
62 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
demo = gr.Interface(
|
65 |
fn=predict_image,
|
66 |
inputs=gr.Image(type="pil"),
|
67 |
outputs=[
|
68 |
-
gr.Textbox(label="
|
|
|
69 |
],
|
70 |
examples=example_list,
|
71 |
title=title,
|
72 |
description=description,
|
|
|
|
|
73 |
)
|
74 |
|
75 |
-
demo.launch()
|
|
|
11 |
|
12 |
def predict_image(image):
|
13 |
predictions = classifier(image)
|
14 |
+
meal_name = predictions[0]['label']
|
15 |
+
recipe_text = getRecipe(meal_name)
|
16 |
+
meal_info = f"This is {meal_name.replace('_', ' ')}."
|
17 |
+
return meal_info, recipe_text
|
18 |
|
19 |
def getRecipe(meal):
|
|
|
20 |
app_id = "24bf0913"
|
21 |
app_key = "03c60f26520f9d25b0d0617e50993aaa"
|
22 |
+
field = ["uri", "label", "image", "ingredientLines", "source", "url"]
|
|
|
23 |
url = "https://api.edamam.com/api/recipes/v2"
|
24 |
|
25 |
+
querystring = {
|
26 |
+
"type": "public",
|
27 |
+
"q": meal.replace("_", " "),
|
28 |
+
"app_id": app_id,
|
29 |
+
"app_key": app_key,
|
30 |
+
"field": field
|
31 |
+
}
|
|
|
|
|
|
|
32 |
|
33 |
response = requests.get(url, params=querystring)
|
|
|
|
|
|
|
34 |
json_object = response.json()
|
35 |
|
36 |
+
returnString = "It is made out of the following ingredients: \n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
for line in json_object["hits"][0]["recipe"]["ingredientLines"]:
|
38 |
returnString += line + "\n"
|
39 |
+
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"]
|
40 |
+
|
41 |
return returnString
|
42 |
|
43 |
title = "Recipifier"
|
44 |
+
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!"
|
45 |
|
46 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
47 |
|
48 |
+
css = """
|
49 |
+
#component-13 {
|
50 |
+
display: none;
|
51 |
+
}
|
52 |
+
"""
|
53 |
+
|
54 |
demo = gr.Interface(
|
55 |
fn=predict_image,
|
56 |
inputs=gr.Image(type="pil"),
|
57 |
outputs=[
|
58 |
+
gr.Textbox(label="Meal", elem_id="meal"),
|
59 |
+
gr.Textbox(label="Recipe")
|
60 |
],
|
61 |
examples=example_list,
|
62 |
title=title,
|
63 |
description=description,
|
64 |
+
css=css,
|
65 |
+
flagging_options=None
|
66 |
)
|
67 |
|
68 |
+
demo.launch()
|