engrphoenix commited on
Commit
e089593
·
verified ·
1 Parent(s): 523a023

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py CHANGED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+ import requests
5
+ import random
6
+
7
+ # Function to fetch recipes based on ingredients
8
+ def get_recipes(ingredients):
9
+ # Spoonacular API Key (Sign up on Spoonacular to get your API key)
10
+ api_key = 'your_spoonacular_api_key' # Replace with your Spoonacular API key
11
+
12
+ # API URL for recipe search
13
+ url = f'https://api.spoonacular.com/recipes/findByIngredients?ingredients={",".join(ingredients)}&number=5&apiKey={api_key}'
14
+
15
+ response = requests.get(url)
16
+
17
+ if response.status_code == 200:
18
+ recipes = response.json()
19
+ return recipes
20
+ else:
21
+ st.error("Failed to fetch recipes. Try again later.")
22
+ return []
23
+
24
+ # Streamlit UI for inputting pantry ingredients
25
+ st.title('AI-Powered Recipe Generator with Pantry Integration')
26
+
27
+ st.write("Enter the ingredients you have in your pantry to generate recipe suggestions!")
28
+
29
+ # Input field for ingredients (comma-separated)
30
+ ingredients_input = st.text_input("Enter ingredients (comma-separated)", "")
31
+
32
+ if ingredients_input:
33
+ ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
34
+
35
+ st.write(f"Looking for recipes with: {', '.join(ingredients)}")
36
+
37
+ # Fetch recipes based on the entered ingredients
38
+ recipes = get_recipes(ingredients)
39
+
40
+ if recipes:
41
+ st.write(f"Here are some recipe suggestions for you:")
42
+ for recipe in recipes:
43
+ st.subheader(recipe['title'])
44
+ st.image(f"https://spoonacular.com/recipeImages/{recipe['id']}-312x231.jpg", width=250)
45
+ st.write(f"[View Recipe](https://spoonacular.com/recipes/{recipe['title'].replace(' ', '-')}-{recipe['id']})")
46
+ st.write("-" * 50)
47
+ else:
48
+ st.write("No recipes found. Try different ingredients.")
49
+