engrphoenix commited on
Commit
05c9152
·
verified ·
1 Parent(s): e089593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -16
app.py CHANGED
@@ -1,8 +1,6 @@
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):
@@ -21,29 +19,67 @@ def get_recipes(ingredients):
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
 
 
 
 
1
  import streamlit as st
2
  import requests
3
+ from PIL import Image
4
 
5
  # Function to fetch recipes based on ingredients
6
  def get_recipes(ingredients):
 
19
  st.error("Failed to fetch recipes. Try again later.")
20
  return []
21
 
22
+ # Streamlit UI setup
23
+ st.set_page_config(page_title="AI-Powered Recipe Generator", page_icon="🍽️", layout="wide")
24
 
25
+ # Add a background image (Optional)
26
+ def add_bg_image(image_path):
27
+ st.markdown(
28
+ f"""
29
+ <style>
30
+ .stApp {{
31
+ background-image: url({image_path});
32
+ background-size: cover;
33
+ background-position: center;
34
+ background-repeat: no-repeat;
35
+ }}
36
+ </style>
37
+ """, unsafe_allow_html=True
38
+ )
39
 
40
+ # Add background image (you can choose your own)
41
+ add_bg_image("https://your-image-url.jpg")
42
 
43
+ # Header with title and icon
44
+ st.title("🍴 AI-Powered Recipe Generator with Pantry Integration")
45
+ st.markdown("""
46
+ Welcome to the AI-powered recipe generator! Simply enter the ingredients you have in your pantry, and we'll suggest some delicious recipes for you. 🥘
47
+ """)
48
+
49
+ # Input field for ingredients (comma-separated)
50
+ ingredients_input = st.text_input("Enter ingredients you have (e.g., eggs, cheese, tomatoes)", "")
51
  if ingredients_input:
52
  ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
53
 
54
+ st.write(f"Looking for recipes with: **{', '.join(ingredients)}**")
55
 
56
  # Fetch recipes based on the entered ingredients
57
  recipes = get_recipes(ingredients)
58
 
59
  if recipes:
60
+ st.markdown("### 🍽️ Here are some recipe suggestions for you:")
61
+
62
+ # Display the recipes in a grid layout
63
+ columns = st.columns(3) # Create a 3-column layout
64
+
65
+ # Loop through the recipes and display them in columns
66
+ for i, recipe in enumerate(recipes):
67
+ col = columns[i % 3] # Distribute recipes across columns
68
+
69
+ with col:
70
+ st.subheader(recipe['title'])
71
+ st.image(f"https://spoonacular.com/recipeImages/{recipe['id']}-312x231.jpg", width=200)
72
+ st.markdown(f"[View Full Recipe](https://spoonacular.com/recipes/{recipe['title'].replace(' ', '-')}-{recipe['id']})", unsafe_allow_html=True)
73
+ st.write("📝 **Ingredients**:")
74
+ st.write(", ".join([ingredient['name'] for ingredient in recipe['missedIngredients']]))
75
+ st.write("-" * 40)
76
+
77
  else:
78
+ st.warning("No recipes found. Try using different ingredients!")
79
+
80
+ # Add a footer for engagement
81
+ st.markdown("""
82
+ ---
83
+ **Need more ideas?** Visit our [Spoonacular API Documentation](https://spoonacular.com/food-api) for more recipe inspiration!
84
+ """)
85