irins commited on
Commit
64b1747
·
verified ·
1 Parent(s): 34bd3e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -43,33 +43,25 @@ def get_recipes(ingredients, max_calories=None, min_protein=None, max_fat=None,
43
  if max_carbs and max_carbs > 0:
44
  params["maxCarbs"] = max_carbs
45
 
46
- # Debugging: Print request parameters
47
- print("Request Params:", params)
48
-
49
  # Send the API request
50
  response = requests.get(url, params=params)
51
-
52
- # Debugging: Print response status
53
- print("Response Status:", response.status_code)
54
-
55
  # Check if the request was successful
56
  if response.status_code == 200:
57
- # Debugging: Print the full API response
58
- print("API Response:", response.json())
59
-
60
- # Extract recipes from the API response
61
  recipes = response.json().get('results', [])
62
  if recipes:
63
  # Format and return the list of recipes as HTML links
64
  html_links = "<br>".join(
65
- [f'<a href="https://spoonacular.com/recipes/{recipe["id"]}" target="_blank">{recipe["title"]}</a>'
66
  for recipe in recipes]
67
  )
 
 
 
68
  return html_links
69
  else:
70
  return "No suitable recipes found."
71
  else:
72
- # Handle API errors
73
  return f"Error fetching recipes: {response.status_code}"
74
 
75
  # Gradio Interface
 
43
  if max_carbs and max_carbs > 0:
44
  params["maxCarbs"] = max_carbs
45
 
 
 
 
46
  # Send the API request
47
  response = requests.get(url, params=params)
48
+
 
 
 
49
  # Check if the request was successful
50
  if response.status_code == 200:
 
 
 
 
51
  recipes = response.json().get('results', [])
52
  if recipes:
53
  # Format and return the list of recipes as HTML links
54
  html_links = "<br>".join(
55
+ [f'<a href="https://spoonacular.com/recipes/{recipe["title"].replace(" ", "-").lower()}-{recipe["id"]}" target="_blank">{recipe["title"]}</a>'
56
  for recipe in recipes]
57
  )
58
+ # Debug: Print each generated URL for the recipes
59
+ for recipe in recipes:
60
+ print(f"Generated URL: https://spoonacular.com/recipes/{recipe['title'].replace(' ', '-').lower()}-{recipe['id']}")
61
  return html_links
62
  else:
63
  return "No suitable recipes found."
64
  else:
 
65
  return f"Error fetching recipes: {response.status_code}"
66
 
67
  # Gradio Interface