nagasurendra commited on
Commit
c2105cb
·
verified ·
1 Parent(s): 49c8e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -52
app.py CHANGED
@@ -1,65 +1,79 @@
1
  import gradio as gr
2
 
3
- # Define the menu categories and dishes
4
- menu_items = [
5
- 'Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan', # Breads
6
- 'Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani', # Veg Curries
7
- 'Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry', # Non-Veg Curries
8
- 'Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani' # Biryani
9
- ]
10
 
11
- # Pairing suggestions based on selected items
12
  def suggest_pairings(selected_items):
13
- suggestions = []
 
14
 
15
- # Suggestions based on bread selection
16
- if any(bread in selected_items for bread in ['Roti', 'Butter Naan', 'Plain Naan', 'Garlic Naan', 'Chilly Naan']):
17
- suggestions.append('Pair with Veg or Non-Veg Curry, and Biryani for a complete meal')
18
-
19
- # Suggestions based on curry selection
20
- if any(curry in selected_items for curry in ['Paneer Butter Masala', 'Kadai Paneer', 'Dum Ka Paneer', 'Mixed Veg Curry', 'Dal Makhani']):
21
- suggestions.append('Veg curries go well with rice-based dishes like Biryani')
22
-
23
- if any(curry in selected_items for curry in ['Chicken Curry', 'Mutton Curry', 'Fish Curry', 'Prawns Curry']):
24
- suggestions.append('Non-Veg curries pair excellently with Biryani and Bread')
25
-
26
- # Suggestions based on Biryani selection
27
- if any(biryani in selected_items for biryani in ['Veg Biryani', 'Paneer Biryani', 'Chicken Biryani', 'Mutton Biryani', 'Fish Biryani', 'Prawns Biryani']):
28
- suggestions.append('Biryani pairs well with raita, naan, or a curry')
29
-
30
- # Customize the suggestion list
31
- if not suggestions:
32
- suggestions.append('Select more dishes to get suggestions!')
33
-
34
- return '\n'.join(suggestions)
35
 
36
- # Function for customizing selected items
37
- def customize_selection(selected_items):
38
- # Display selected items and provide an option to add custom ingredients
39
- selected_items_str = ", ".join(selected_items)
40
- return f"You've selected: {selected_items_str}. You can customize your dish by adding ingredients below."
 
 
 
 
 
 
 
 
 
41
 
42
- # Create the Gradio Interface
43
- def create_app():
44
- # Input: Single selection box to select multiple items
45
- menu_input = gr.CheckboxGroup(label="Select Items from Menu", choices=menu_items)
 
 
46
 
47
- # Output: Pairing suggestions and customization box
48
- pairing_output = gr.Textbox(label="Pairing Suggestions")
49
- customization_output = gr.Textbox(label="Customization Box", interactive=True)
50
 
51
- # Set up the Gradio Interface
52
- interface = gr.Interface(
53
- fn=lambda selected_items: (suggest_pairings(selected_items), customize_selection(selected_items)),
54
- inputs=menu_input,
55
- outputs=[pairing_output, customization_output],
56
- live=True
57
- )
 
 
58
 
59
- return interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- # Launch the Gradio interface
62
- interface = create_app()
63
- interface.launch()
64
 
65
 
 
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
+ # Function to provide suggestions based on selection
10
  def suggest_pairings(selected_items):
11
+ # Create a set for selected items for easier matching
12
+ selected_set = set(selected_items)
13
 
14
+ # Initial suggestions
15
+ breads_suggested = []
16
+ veg_curries_suggested = []
17
+ non_veg_curries_suggested = []
18
+ biryani_suggested = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ # Suggest items based on selection logic
21
+ if '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:
22
+ veg_curries_suggested = veg_curries
23
+ non_veg_curries_suggested = non_veg_curries
24
+ elif '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:
25
+ breads_suggested = breads
26
+ biryani_suggested = biryani
27
+ elif 'Chicken Curry' in selected_set or 'Mutton Curry' in selected_set or 'Fish Curry' in selected_set or 'Prawns Curry' in selected_set:
28
+ breads_suggested = breads
29
+ biryani_suggested = biryani
30
+ elif '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:
31
+ breads_suggested = breads
32
+ veg_curries_suggested = veg_curries
33
+ non_veg_curries_suggested = non_veg_curries
34
 
35
+ # If nothing selected, suggest everything
36
+ if not selected_items:
37
+ breads_suggested = breads
38
+ veg_curries_suggested = veg_curries
39
+ non_veg_curries_suggested = non_veg_curries
40
+ biryani_suggested = biryani
41
 
42
+ return breads_suggested, veg_curries_suggested, non_veg_curries_suggested, biryani_suggested
 
 
43
 
44
+ # Function to handle user input and generate suggestions
45
+ def menu_selection(selected_items, custom_ingredient):
46
+ # Get suggestions based on selected items
47
+ breads_suggested, veg_curries_suggested, non_veg_curries_suggested, biryani_suggested = suggest_pairings(selected_items)
48
+
49
+ # Combine suggestions into one string for easy display
50
+ suggestions = 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)}"
51
+
52
+ return suggestions, f"Custom Ingredient: {custom_ingredient}"
53
 
54
+ # Gradio UI
55
+ def create_ui():
56
+ # Define the menu with all items for selection
57
+ menu_items = breads + veg_curries + non_veg_curries + biryani
58
+
59
+ # Gradio interface with the selection box and custom input box
60
+ with gr.Blocks() as demo:
61
+ with gr.Row():
62
+ menu_box = gr.CheckboxGroup(label="Select Menu Items", choices=menu_items, type="value")
63
+ custom_box = gr.Textbox(label="Customize Dish (Add Ingredients)", placeholder="e.g., Extra Cheese, Spicy", lines=2)
64
+
65
+ with gr.Row():
66
+ next_button = gr.Button("Next")
67
+
68
+ suggestions_output = gr.Textbox(label="Suggestions Based on Your Selection", interactive=False)
69
+
70
+ # Define the event when "Next" is clicked
71
+ next_button.click(fn=menu_selection, inputs=[menu_box, custom_box], outputs=[suggestions_output, custom_box])
72
+
73
+ return demo
74
 
75
+ # Run the app
76
+ demo = create_ui()
77
+ demo.launch()
78
 
79