Spaces:
Sleeping
Sleeping
Restart container
Browse files
app.py
CHANGED
@@ -24,30 +24,38 @@ def getRecipe(meal):
|
|
24 |
"x-rapidapi-host": "gustar-io-deutsche-rezepte.p.rapidapi.com",
|
25 |
"Content-Type": "application/json"
|
26 |
}
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
instructions_list
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
title = "Recipifier"
|
53 |
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!"
|
|
|
24 |
"x-rapidapi-host": "gustar-io-deutsche-rezepte.p.rapidapi.com",
|
25 |
"Content-Type": "application/json"
|
26 |
}
|
27 |
+
try:
|
28 |
+
response = requests.post(url, json=payload, headers=headers)
|
29 |
+
response.raise_for_status() # Raise an error for bad status codes
|
30 |
+
|
31 |
+
data = response.json()
|
32 |
+
|
33 |
+
# Format ingredients list
|
34 |
+
ingredients_list = "Zutaten:\n"
|
35 |
+
for ingredient in data['ingredients']:
|
36 |
+
amount = ingredient.get('amount', '')
|
37 |
+
unit = ingredient.get('unit', '')
|
38 |
+
name = ingredient['name']
|
39 |
+
ingredients_list += f"- {amount} {unit} {name}\n".strip() + '\n'
|
40 |
+
|
41 |
+
# Format instructions list
|
42 |
+
instructions_list = "\nZubereitung:\n"
|
43 |
+
for step in data['instructions']:
|
44 |
+
instructions_list += f"{step}\n"
|
45 |
+
|
46 |
+
# Format the entire recipe
|
47 |
+
formatted_recipe = f"{data['title']}\n"
|
48 |
+
formatted_recipe += f"Portionen: {data['portions']}\n"
|
49 |
+
formatted_recipe += f"Gesamtzeit: {data['totalTime'] // 60} Minuten\n\n"
|
50 |
+
formatted_recipe += ingredients_list + instructions_list
|
51 |
+
|
52 |
+
return formatted_recipe
|
53 |
+
|
54 |
+
except requests.exceptions.RequestException as e:
|
55 |
+
return f"An error occurred while fetching the recipe: {str(e)}"
|
56 |
+
|
57 |
+
except json.decoder.JSONDecodeError:
|
58 |
+
return "Error: Unable to decode the JSON response from the API."
|
59 |
|
60 |
title = "Recipifier"
|
61 |
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!"
|