aichatbot01 / app.py
Subbu1304's picture
Update app.py
33933ea verified
raw
history blame
5.11 kB
import gradio as gr
# Step 1: Greeting the user and asking if they'd like to customize food
def start_conversation(user_input):
# Checking if the input is a positive response
if user_input.lower() in ["yes", "yeah"]:
return "Great! Please select a food category:"
else:
return "Okay, let me know if you change your mind!"
# Step 2: Show categories based on the user's interest
def select_category(selected_category):
categories = {
"Veg": "Great! You selected Veg. Now, please select your nutrition preference.",
"Non-Veg": "Great! You selected Non-Veg. Now, please select your nutrition preference.",
"Vegan": "Great! You selected Vegan. Now, please select your nutrition preference.",
"Pasta & Noodles": "Great! You selected Pasta & Noodles. Now, please select your nutrition preference.",
"Breads & Baked Goods": "Great! You selected Breads & Baked Goods. Now, please select your nutrition preference."
}
return categories.get(selected_category, "Please select a valid category.")
# Step 3: Show nutrition options based on the selected category
def select_nutrition(selected_nutrition):
nutrition_options = {
"Protein Rich": "Now, please select ingredients from the list below.",
"Low Carbs": "Now, please select ingredients from the list below.",
"Gluten-Free": "Now, please select ingredients from the list below."
}
return nutrition_options.get(selected_nutrition, "Please select a valid nutrition option.")
# Step 4: Show ingredients based on the category and nutrition selection
def show_ingredients(selected_category, selected_nutrition):
# Ingredients based on category and nutrition preference
ingredients = {
"Veg": ["Paneer", "Potato", "Cabbage", "Gobi"],
"Non-Veg": ["Chicken", "Fish", "Mutton"],
"Vegan": ["Tofu", "Tempeh", "Seitan"],
"Pasta & Noodles": ["Whole Wheat Pasta", "Rice Noodles"],
"Breads & Baked Goods": ["Whole Grain Bread", "Gluten-Free Bread"]
}
return f"Here are the ingredients available for {selected_category} with {selected_nutrition} option: " + ", ".join(ingredients.get(selected_category, []))
# Step 5: Show dishes based on the selected ingredient
def show_dishes(selected_ingredient):
dishes = {
"Paneer": ["Paneer Tikka", "Paneer Curry", "Paneer Manchurian", "Paneer Butter Masala"],
"Potato": ["Aloo Dal", "Potato and Chickpea Salad", "Paneer-Stuffed Potatoes", "Potato and Black Bean Tacos"],
"Cabbage": ["Cabbage and Chickpea Curry", "Cabbage Stir-Fry with Tofu", "Cabbage and Lentil Soup"],
"Chicken": ["Grilled Chicken Breast", "Chicken Tikka Masala", "Chicken Stir-Fry", "Chicken Biryani"],
"Fish": ["Grilled Salmon", "Fish Curry", "Baked Fish with Herbs", "Fish Tacos"],
"Mutton": ["Mutton Curry", "Mutton Biryani", "Grilled Lamb Chops", "Mutton Rogan Josh"],
"Tofu": ["Tofu Stir-Fry", "Crispy Tofu Nuggets", "Tofu Scramble", "Tofu Curry"],
"Tempeh": ["Tempeh Bacon", "BBQ Tempeh", "Tempeh Stir-Fry", "Marinated Tempeh"],
"Seitan": ["Seitan Steak", "Seitan Wings", "Seitan Stir-Fry", "Seitan Curry"]
}
return f"Based on your selection, here are the food items you can make: " + ", ".join(dishes.get(selected_ingredient, []))
# Gradio interface setup
def create_gradio_interface():
# Step-by-step interaction using Gradio components
with gr.Blocks() as demo:
gr.Markdown("# Food Customization Assistant")
gr.Markdown("Talk to the bot and customize your food preferences based on category.")
# Greeting Step
user_input = gr.Textbox(label="Your Message", placeholder="Type 'yes' or 'yeah' to begin.", lines=1)
bot_response = gr.Textbox(label="Bot Response", lines=2)
# First interaction: Ask user if they want to customize food
user_input.submit(start_conversation, user_input, bot_response)
# Category Selection
category_dropdown = gr.Dropdown(
choices=["Veg", "Non-Veg", "Vegan", "Pasta & Noodles", "Breads & Baked Goods"],
label="Select Food Category"
)
category_dropdown.change(select_category, category_dropdown, bot_response)
# Nutrition Preferences
nutrition_dropdown = gr.Dropdown(
choices=["Protein Rich", "Low Carbs", "Gluten-Free"],
label="Select Nutrition Preference"
)
nutrition_dropdown.change(select_nutrition, nutrition_dropdown, bot_response)
# Show Ingredients based on category & nutrition
ingredients_output = gr.Textbox(label="Ingredients List", lines=2)
ingredients_output.change(show_ingredients, [category_dropdown, nutrition_dropdown], ingredients_output)
# Ingredient Selection
ingredient_dropdown = gr.Dropdown(label="Select Ingredient")
ingredient_dropdown.change(show_dishes, ingredient_dropdown, bot_response)
# Start Gradio Interface
demo.launch()
if __name__ == "__main__":
create_gradio_interface()