|
|
import streamlit as st |
|
|
import random |
|
|
|
|
|
|
|
|
|
|
|
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." |
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
def suggest_dishes(ingredients): |
|
|
suggested_dishes = [] |
|
|
|
|
|
for dish, details in recipe_data.items(): |
|
|
|
|
|
if any(ingredient in ingredients for ingredient in details['ingredients']): |
|
|
suggested_dishes.append(dish) |
|
|
|
|
|
|
|
|
return random.sample(suggested_dishes, 3) if len(suggested_dishes) >= 3 else suggested_dishes |
|
|
|
|
|
|
|
|
st.title("Cooking Suggestion App") |
|
|
st.write("Enter 1 or 2 ingredients to get recipe suggestions:") |
|
|
|
|
|
|
|
|
ingredients_input = st.text_input("Enter ingredients (comma separated):") |
|
|
|
|
|
if st.button("Suggest Dishes"): |
|
|
if ingredients_input: |
|
|
|
|
|
ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')] |
|
|
st.write("Entered Ingredients:", ingredients) |
|
|
|
|
|
if 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.") |
|
|
|