nagasurendra commited on
Commit
d0a9d46
·
verified ·
1 Parent(s): 64e4517

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -59
app.py CHANGED
@@ -1,67 +1,59 @@
1
  import gradio as gr
2
 
3
- # Define menu items
4
  breads = ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan']
5
  veg_curries = ['Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani']
6
  non_veg_curries = ['Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry']
7
  biryani = ['Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani']
8
 
9
- # Combine everything into one picklist for user selection
10
- menu_items = breads + veg_curries + non_veg_curries + biryani
11
-
12
- # Function to generate suggestions based on selected items
13
- def generate_suggestions(selected_items):
14
- suggestions = []
15
-
16
- # If bread is selected, suggest curries (veg and non-veg)
17
- if any(item in selected_items for item in breads):
18
- suggestions.extend(veg_curries + non_veg_curries)
19
-
20
- # If any curry is selected, suggest breads and biryani
21
- if any(item in selected_items for item in veg_curries + non_veg_curries):
22
- suggestions.extend(breads + biryani)
23
-
24
- # If any biryani is selected, suggest breads and curries
25
- if any(item in selected_items for item in biryani):
26
- suggestions.extend(breads + veg_curries + non_veg_curries)
27
-
28
- # Remove already selected items from the suggestions
29
- suggestions = [item for item in suggestions if item not in selected_items]
 
 
 
 
 
 
30
 
31
- return suggestions
32
-
33
- # Function for customizing the selected dishes (optional ingredients)
34
- def customize_dishes(selected_items, custom_ingredients):
35
- return f"Selected dishes: {', '.join(selected_items)}\nCustom ingredients: {custom_ingredients}"
36
-
37
- # Define Gradio interface
38
- def create_interface():
39
- with gr.Blocks() as demo:
40
- with gr.Row():
41
- menu = gr.CheckboxGroup(choices=menu_items, label="Select Menu Items", interactive=True)
42
- suggestion_box = gr.Dropdown(label="Suggestions", interactive=True)
43
- custom_box = gr.Textbox(label="Add Custom Ingredients", placeholder="e.g., extra cheese, spicy", lines=2)
44
- next_button = gr.Button("Next")
45
- output_box = gr.Textbox(label="Final Selection", placeholder="Your final selection will appear here")
46
-
47
- # Function to handle the logic when the user selects items
48
- def handle_selection(selected_items, custom_ingredients):
49
- # Get pairing suggestions based on selected items
50
- suggestions = generate_suggestions(selected_items)
51
- suggestion_box.update(choices=suggestions)
52
- # Add custom ingredients to the selection
53
- final_selection = customize_dishes(selected_items, custom_ingredients)
54
- output_box.update(value=final_selection)
55
- return suggestions, final_selection
56
-
57
- # Set up the interaction logic
58
- menu.change(fn=handle_selection, inputs=[menu, custom_box], outputs=[suggestion_box, output_box])
59
- next_button.click(fn=handle_selection, inputs=[menu, custom_box], outputs=output_box)
60
-
61
- return demo
62
-
63
- # Create the interface
64
- demo = create_interface()
65
-
66
- # Launch the Gradio app
67
- demo.launch()
 
1
  import gradio as gr
2
 
3
+ # Define menu categories
4
  breads = ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan']
5
  veg_curries = ['Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani']
6
  non_veg_curries = ['Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry']
7
  biryani = ['Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani']
8
 
9
+ # Define the logic for suggestions
10
+ def get_suggestions(selected_items):
11
+ # If bread is selected, suggest curries and biryanis
12
+ if any(bread in selected_items for bread in breads):
13
+ suggestions = veg_curries + non_veg_curries
14
+ remaining_category = biryani # suggest biryanis if bread is selected
15
+ # If curries are selected, suggest bread and biryanis
16
+ elif any(curry in selected_items for curry in veg_curries + non_veg_curries):
17
+ suggestions = breads # suggest breads if curries are selected
18
+ remaining_category = biryani # suggest biryanis if curries are selected
19
+ # If biryanis are selected, suggest breads and curries
20
+ elif any(bir in selected_items for bir in biryani):
21
+ suggestions = breads + veg_curries + non_veg_curries # suggest breads and curries if biryanis are selected
22
+ remaining_category = [] # no remaining category if biryanis are selected
23
+ else:
24
+ suggestions = []
25
+ remaining_category = []
26
+
27
+ return suggestions, remaining_category
28
+
29
+ # Define the customization options box
30
+ def customize_selections(selected_items, custom_ingredients):
31
+ return f"Selected Items: {', '.join(selected_items)}\nCustom Ingredients: {custom_ingredients}"
32
+
33
+ # Gradio interface
34
+ def select_menu_and_customize(menu_items, custom_ingredients):
35
+ suggestions, remaining_category = get_suggestions(menu_items)
36
 
37
+ # Return suggestions for the next selection step
38
+ return suggestions, remaining_category, customize_selections(menu_items, custom_ingredients)
39
+
40
+ # Create the Gradio interface
41
+ menu_options = breads + veg_curries + non_veg_curries + biryani
42
+
43
+ # Create the Gradio interface
44
+ interface = gr.Interface(
45
+ fn=select_menu_and_customize,
46
+ inputs=[
47
+ gr.CheckboxGroup(choices=menu_options, label="Select your menu items"),
48
+ gr.Textbox(placeholder="Add any custom ingredients here", label="Custom Ingredients")
49
+ ],
50
+ outputs=[
51
+ gr.CheckboxGroup(label="Suggestions based on your selections"),
52
+ gr.Textbox(label="Remaining options"),
53
+ gr.Textbox(label="Final Order Summary")
54
+ ],
55
+ live=True, # This ensures suggestions update as the user makes selections
56
+ )
57
+
58
+ # Launch the app
59
+ interface.launch()