recipe_bot / app.py
dipsmom's picture
Update app.py
611963e verified
import random
import gradio as gr
# Initialize recipes data
recipes = [
{
"name": "Butter Chicken",
"ingredients": [
"Chicken",
"Butter",
"Tomato puree",
"Cream",
"Spices (garam masala, turmeric, chili powder)"
],
"steps": "1. Marinate the chicken with spices and yogurt for 1 hour.\n2. Cook the chicken in butter until golden brown.\n3. Prepare the gravy with tomato puree, cream, and spices.\n4. Add the cooked chicken to the gravy and simmer for 10 minutes.\n5. Serve with naan or rice."
},
{
"name": "Masala Dosa",
"ingredients": [
"Rice",
"Urad dal",
"Potatoes",
"Onions",
"Curry leaves",
"Spices (mustard seeds, turmeric, green chilies)"
],
"steps": "1. Soak rice and urad dal for 6 hours and grind to make a batter.\n2. Ferment the batter overnight.\n3. Prepare the potato filling by cooking mashed potatoes with onions, curry leaves, and spices.\n4. Spread the batter on a hot tawa to make a thin dosa.\n5. Add the potato filling and fold the dosa. Serve with chutney and sambar."
},
{
"name": "Paneer Tikka",
"ingredients": [
"Paneer",
"Yogurt",
"Spices (turmeric, chili powder, garam masala)",
"Capsicum",
"Onions"
],
"steps": "1. Marinate paneer cubes with yogurt and spices for 30 minutes.\n2. Skewer the paneer with capsicum and onion pieces.\n3. Grill or bake the skewers until golden brown.\n4. Serve hot with mint chutney."
},
{
"name": "Chole Bhature",
"ingredients": [
"Chickpeas",
"Onions",
"Tomatoes",
"Spices (chole masala, turmeric, chili powder)",
"Flour (for bhature)"
],
"steps": "1. Soak chickpeas overnight and boil until soft.\n2. Prepare the gravy with onions, tomatoes, and spices.\n3. Add the boiled chickpeas and simmer for 15 minutes.\n4. Knead the flour to make a dough and roll into bhature.\n5. Deep fry the bhature and serve with chole."
},
{
"name": "Biryani",
"ingredients": [
"Basmati rice",
"Chicken or vegetables",
"Yogurt",
"Onions",
"Spices (biryani masala, turmeric, saffron)"
],
"steps": "1. Marinate chicken or vegetables with yogurt and spices.\n2. Cook basmati rice until 70% done.\n3. Layer the marinated chicken/vegetables and rice in a pot.\n4. Add fried onions and saffron milk on top.\n5. Cover and cook on low heat for 30 minutes. Serve hot."
}
]
# Functions for Recipe Bot
def list_recipes():
recipe_names = [recipe['name'] for recipe in recipes]
return "\n".join(f"{i + 1}. {name}" for i, name in enumerate(recipe_names))
def show_recipe_details(recipe_name):
if not recipe_name.strip():
return "Please enter a recipe name."
for recipe in recipes:
if recipe["name"].lower() == recipe_name.lower():
ingredients = "\n".join(f"- {ing}" for ing in recipe['ingredients'])
steps = recipe['steps']
return f"Recipe: {recipe['name']}\n\nIngredients:\n{ingredients}\n\nSteps:\n{steps}"
return f"Recipe '{recipe_name}' not found. Please check the name or try again."
def add_new_recipe(name, ingredients, steps):
# Check for existing recipe with the same name
for recipe in recipes:
if recipe["name"].lower() == name.lower():
return f"Recipe '{name}' already exists. Please use a unique name."
new_recipe = {
"name": name,
"ingredients": [ing.strip() for ing in ingredients.split(',')],
"steps": steps
}
recipes.append(new_recipe)
return f"Recipe '{name}' added successfully!"
def random_recipe():
if recipes:
recipe = random.choice(recipes)
return show_recipe_details(recipe["name"])
return "No recipes available."
# Gradio App
def recipe_action(choice, name, ingredients, steps):
if choice == "List Recipes":
return list_recipes()
elif choice == "View Recipe Details":
return show_recipe_details(name)
elif choice == "Add New Recipe":
return add_new_recipe(name, ingredients, steps)
elif choice == "Random Recipe":
return random_recipe()
with gr.Blocks() as interface:
choice = gr.Radio(["List Recipes", "View Recipe Details", "Add New Recipe", "Random Recipe"], label="Choose an Action")
name = gr.Textbox(label="Recipe Name (for View/Add)", placeholder="Enter new recipe name here...")
ingredients = gr.Textbox(label="Ingredients (comma-separated, for Add)", placeholder="Enter ingredients here...")
steps = gr.Textbox(label="Steps (for Add)", placeholder="Enter preparation steps here...")
output = gr.Textbox(label="Output", interactive=False)
# Trigger the update based on the user's choice
choice.change(fn=recipe_action, inputs=[choice, name, ingredients, steps], outputs=output)
# Launch the app
interface.launch()