larimei commited on
Commit
3a7e3d7
1 Parent(s): 2400e07

Restart container

Browse files
Files changed (1) hide show
  1. app.py +32 -24
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
- response = requests.post(url, json=payload, headers=headers)
28
-
29
- data = response.json()
30
-
31
- # Zutatenliste formatieren
32
- ingredients_list = "Zutaten:\n"
33
- for ingredient in data['ingredients']:
34
- amount = ingredient.get('amount', '')
35
- unit = ingredient.get('unit', '')
36
- name = ingredient['name']
37
- ingredients_list += f"- {amount} {unit} {name}\n".strip() + '\n'
38
-
39
- # Zubereitungsschritte formatieren
40
- instructions_list = "\nZubereitung:\n"
41
- for step in data['instructions']:
42
- instructions_list += f"{step}\n"
43
-
44
- # Gesamtes Rezept formatieren
45
- formatted_recipe = f"{data['title']}\n"
46
- formatted_recipe += f"Portionen: {data['portions']}\n"
47
- formatted_recipe += f"Gesamtzeit: {data['totalTime'] // 60} Minuten\n\n"
48
- formatted_recipe += ingredients_list + instructions_list
49
-
50
- return formatted_recipe
 
 
 
 
 
 
 
 
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!"