Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ from transformers import pipeline
|
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
4 |
import os
|
|
|
|
|
5 |
|
6 |
model_name = "larimei/food-classification-ai"
|
7 |
|
@@ -9,8 +11,46 @@ classifier = pipeline("image-classification", model=model_name)
|
|
9 |
|
10 |
def predict_image(image):
|
11 |
predictions = classifier(image)
|
12 |
-
return predictions[0]['label']
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
title = "Recipifier"
|
16 |
description = "blablabla"
|
|
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
+
import requests
|
6 |
+
import json
|
7 |
|
8 |
model_name = "larimei/food-classification-ai"
|
9 |
|
|
|
11 |
|
12 |
def predict_image(image):
|
13 |
predictions = classifier(image)
|
14 |
+
return getRecipe(predictions[0]['label'])
|
15 |
|
16 |
+
def getRecipe(meal):
|
17 |
+
#meal = "hamburger"
|
18 |
+
app_id = "24bf0913"
|
19 |
+
app_key = "03c60f26520f9d25b0d0617e50993aaa"
|
20 |
+
#field = ["label"]
|
21 |
+
field = ["uri","label","image","ingredientLines","source","url"]
|
22 |
+
url = "https://api.edamam.com/api/recipes/v2"
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
#url2 = "https://api.edamam.com/api/recipes/v2?type=public&q=chicken%20curry&app_id=24bf0913&app_key=03c60f26520f9d25b0d0617e50993aaa"
|
27 |
+
|
28 |
+
querystring = {"type":"public",
|
29 |
+
"q": meal.replace("_"," "),
|
30 |
+
"app_id": app_id,
|
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 |
+
json_formatted_str = json.dumps(json_object["hits"][0], indent=2) #nur das erste der 20 aus der liste
|
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 |
+
#just one result
|
53 |
+
return json_object["hits"][0]["recipe"]["ingredientLines"]
|
54 |
|
55 |
title = "Recipifier"
|
56 |
description = "blablabla"
|