Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import gradio as gr# Define the menu categories and dishesmenu_items = ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan', # Breads'Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani', # Veg Curries'Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry', # Non-Veg Curries'Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani' # Biryani]# Pairing suggestions based on selected itemsdef suggest_pairings(selected_items):suggestions = []# Suggestions based on bread selectionif any(bread in selected_items for bread in ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan']):suggestions.append('Pair with Veg or Non-Veg Curry, and Biryani for a complete meal')# Suggestions based on curry selectionif any(curry in selected_items for curry in ['Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani']):suggestions.append('Veg curries go well with rice-based dishes like Biryani')if any(curry in selected_items for curry in ['Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry']):suggestions.append('Non-Veg curries pair excellently with Biryani and Bread')# Suggestions based on Biryani selectionif any(biryani in selected_items for biryani in ['Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani']):suggestions.append('Biryani pairs well with raita, naan, or a curry')# Customize the suggestion listif not suggestions:suggestions.append('Select more dishes to get suggestions!')return '\n'.join(suggestions)# Function for customizing selected itemsdef customize_selection(selected_items):# Display selected items and provide an option to add custom ingredientsselected_items_str = ", ".join(selected_items)return f"You've selected: {selected_items_str}. You can customize your dish by adding ingredients below."# Create the Gradio Interfacedef create_app():# Input: Single selection box to select multiple itemsmenu_input = gr.CheckboxGroup(label="Select Items from Menu", choices=menu_items)# Output: Pairing suggestions and customization boxpairing_output = gr.Textbox(label="Pairing Suggestions")customization_output = gr.Textbox(label="Customization Box", interactive=True)# Set up the Gradio Interfaceinterface = gr.Interface(fn=lambda selected_items: (suggest_pairings(selected_items), customize_selection(selected_items)),inputs=menu_input,outputs=[pairing_output, customization_output],live=True)return interface# Launch the Gradio interfaceinterface = create_app()interface.launch()12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import gradio as gr# Define menu categoriesbreads = ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan']veg_curries = ['Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani']non_veg_curries = ['Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry']biryani = ['Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani']# Function to provide suggestions based on selectiondef suggest_pairings(selected_items):# Create a set for selected items for easier matchingselected_set = set(selected_items)# Initial suggestionsbreads_suggested = []veg_curries_suggested = []non_veg_curries_suggested = []biryani_suggested = []# Suggest items based on selection logicif 'Roti' in selected_set or 'Butter Naan' in selected_set or 'Plain Naan' in selected_set or 'Garlic Naan' in selected_set or 'Chilly Naan' in selected_set:veg_curries_suggested = veg_curriesnon_veg_curries_suggested = non_veg_currieselif 'Paneer Butter Masala' in selected_set or 'Kadai Paneer' in selected_set or 'Dum Ka Paneer' in selected_set or 'Mixed Veg Curry' in selected_set or 'Dal Makhani' in selected_set:breads_suggested = breadsbiryani_suggested = biryanielif 'Chicken Curry' in selected_set or 'Mutton Curry' in selected_set or 'Fish Curry' in selected_set or 'Prawns Curry' in selected_set:breads_suggested = breadsbiryani_suggested = biryanielif 'Veg Biryani' in selected_set or 'Paneer Biryani' in selected_set or 'Chicken Biryani' in selected_set or 'Mutton Biryani' in selected_set or 'Fish Biryani' in selected_set or 'Prawns Biryani' in selected_set:breads_suggested = breadsveg_curries_suggested = veg_curriesnon_veg_curries_suggested = non_veg_curries# If nothing selected, suggest everythingif not selected_items:breads_suggested = breadsveg_curries_suggested = veg_curriesnon_veg_curries_suggested = non_veg_curriesbiryani_suggested = biryanireturn breads_suggested, veg_curries_suggested, non_veg_curries_suggested, biryani_suggested# Function to handle user input and generate suggestionsdef menu_selection(selected_items, custom_ingredient):# Get suggestions based on selected itemsbreads_suggested, veg_curries_suggested, non_veg_curries_suggested, biryani_suggested = suggest_pairings(selected_items)# Combine suggestions into one string for easy displaysuggestions = f"Suggested Pairings:\n\nBreads: {', '.join(breads_suggested)}\nVeg Curries: {', '.join(veg_curries_suggested)}\nNon-Veg Curries: {', '.join(non_veg_curries_suggested)}\nBiryani: {', '.join(biryani_suggested)}"return suggestions, f"Custom Ingredient: {custom_ingredient}"# Gradio UIdef create_ui():# Define the menu with all items for selectionmenu_items = breads + veg_curries + non_veg_curries + biryani# Gradio interface with the selection box and custom input boxwith gr.Blocks() as demo:with gr.Row():menu_box = gr.CheckboxGroup(label="Select Menu Items", choices=menu_items, type="value")custom_box = gr.Textbox(label="Customize Dish (Add Ingredients)", placeholder="e.g., Extra Cheese, Spicy", lines=2)with gr.Row():next_button = gr.Button("Next")suggestions_output = gr.Textbox(label="Suggestions Based on Your Selection", interactive=False)# Define the event when "Next" is clickednext_button.click(fn=menu_selection, inputs=[menu_box, custom_box], outputs=[suggestions_output, custom_box])return demo# Run the appdemo = create_ui()demo.launch()
app.py+66-52