Recipe / app.py
SanaAdeel's picture
Update app.py
09e8a31 verified
import streamlit as st
import random
# Sample dataset for dish suggestions and recipes
# Ideally, this would be a large dataset or database
recipe_data = {
"Spaghetti Carbonara": {
"ingredients": ["spaghetti", "eggs", "cheese", "pancetta", "garlic", "black pepper"],
"recipe": "1. Cook spaghetti. 2. Mix eggs and cheese. 3. Fry pancetta and garlic. 4. Combine all and season with pepper."
},
"Chicken Salad": {
"ingredients": ["chicken", "lettuce", "tomato", "cucumber", "olive oil", "lemon"],
"recipe": "1. Grill the chicken. 2. Prepare the salad with lettuce, tomato, and cucumber. 3. Dress with olive oil and lemon."
},
"Beef Stew": {
"ingredients": ["beef", "carrots", "potatoes", "onion", "garlic", "beef broth"],
"recipe": "1. Brown the beef. 2. Add carrots, potatoes, and onion. 3. Pour in beef broth and simmer until tender."
},
"Vegetable Stir Fry": {
"ingredients": ["carrot", "broccoli", "bell pepper", "soy sauce", "ginger", "garlic"],
"recipe": "1. Stir-fry the vegetables in oil. 2. Add soy sauce and ginger. 3. Cook until tender."
},
"Pasta Salad": {
"ingredients": ["pasta", "tomato", "cucumber", "olive oil", "balsamic vinegar"],
"recipe": "1. Cook pasta. 2. Chop vegetables. 3. Mix all ingredients and season with olive oil and balsamic vinegar."
},
# Add more recipes as needed
}
# Function to suggest dishes based on ingredients
def suggest_dishes(ingredients):
suggested_dishes = []
for dish, details in recipe_data.items():
# Check if the dish contains at least one of the entered ingredients
if any(ingredient in ingredients for ingredient in details['ingredients']):
suggested_dishes.append(dish)
# Randomly suggest 3 dishes from the possible matches (if there are enough)
return random.sample(suggested_dishes, 3) if len(suggested_dishes) >= 3 else suggested_dishes
# Streamlit app
st.title("Cooking Suggestion App")
st.write("Enter 1 or 2 ingredients to get recipe suggestions:")
# Ingredients input
ingredients_input = st.text_input("Enter ingredients (comma separated):")
if st.button("Suggest Dishes"):
if ingredients_input:
# Split input into individual ingredients
ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
st.write("Entered Ingredients:", ingredients)
if ingredients:
# Suggest dishes based on entered ingredients
suggested_dishes = suggest_dishes(ingredients)
if suggested_dishes:
st.write("Suggested Dishes:")
selected_dish = st.selectbox("Choose a dish", suggested_dishes)
if selected_dish:
st.write(f"Recipe for {selected_dish}:")
st.write(recipe_data[selected_dish]["recipe"])
else:
st.write("No dishes found for the entered ingredients.")
else:
st.write("No valid ingredients entered.")
else:
st.write("Please enter some ingredients.")