nagasurendra commited on
Commit
b16d730
·
verified ·
1 Parent(s): 013b172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -36,12 +36,49 @@ def filter_menu(preference):
36
  </div>
37
  <div style="flex-shrink: 0; text-align: center;">
38
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
39
- <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
40
  </div>
41
  </div>
42
  """
43
  return html_content
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Gradio app definition
46
  def app():
47
  with gr.Blocks(title="Dynamic Menu with Filters") as demo:
@@ -57,12 +94,17 @@ def app():
57
  # Output area for menu items
58
  menu_output = gr.HTML(value=filter_menu("All"))
59
 
 
 
 
60
  # Define interactivity
61
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
 
62
 
63
  # Layout
64
  gr.Row([selected_preference])
65
  gr.Row(menu_output)
 
66
 
67
  return demo
68
 
 
36
  </div>
37
  <div style="flex-shrink: 0; text-align: center;">
38
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
39
+ <button onclick="showPopup('{item['Dish Name']}')" style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add</button>
40
  </div>
41
  </div>
42
  """
43
  return html_content
44
 
45
+ # Function to generate the popup content dynamically
46
+ def generate_popup(item_name):
47
+ menu_data = load_menu()
48
+ item = menu_data[menu_data['Dish Name'] == item_name].iloc[0]
49
+
50
+ # Dynamic HTML for the popup
51
+ popup_content = f"""
52
+ <div style="background-color: white; padding: 20px; border-radius: 8px; width: 80%; margin: auto; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 1000;">
53
+ <img src="{item['Image URL']}" alt="{item_name}" style="width: 100%; border-radius: 8px; margin-bottom: 20px;">
54
+ <h2>{item_name}</h2>
55
+ <p>{item['Description']}</p>
56
+ <p style="font-size: 18px; color: #333;"><strong>Price:</strong> ${item['Price ($)']}</p>
57
+ <h3>Choose a Spice Level:</h3>
58
+ <div style="display: flex; gap: 10px;">
59
+ <label><input type="radio" name="spice" value="American Mild"> American Mild</label>
60
+ <label><input type="radio" name="spice" value="American Medium"> American Medium</label>
61
+ <label><input type="radio" name="spice" value="American Spicy"> American Spicy</label>
62
+ <label><input type="radio" name="spice" value="Indian Mild"> Indian Mild</label>
63
+ <label><input type="radio" name="spice" value="Indian Medium"> Indian Medium</label>
64
+ <label><input type="radio" name="spice" value="Indian Spicy"> Indian Spicy</label>
65
+ </div>
66
+ <h3>Biryani Extras:</h3>
67
+ <div style="display: flex; flex-wrap: wrap; gap: 10px;">
68
+ <label><input type="checkbox" name="extras" value="Extra Raitha 4oz"> Extra Raitha 4oz ($1)</label>
69
+ <label><input type="checkbox" name="extras" value="Extra Raitha 8oz"> Extra Raitha 8oz ($2)</label>
70
+ <label><input type="checkbox" name="extras" value="Extra Salan 4oz"> Extra Salan 4oz ($1)</label>
71
+ <label><input type="checkbox" name="extras" value="Extra Onion"> Extra Onion ($1)</label>
72
+ </div>
73
+ <h3>Special Instructions:</h3>
74
+ <textarea placeholder="Add any requests here." style="width: 100%; height: 100px;"></textarea>
75
+ <h3>Quantity:</h3>
76
+ <input type="number" value="1" min="1" style="width: 50px;">
77
+ <button style="background-color: purple; color: white; padding: 10px 20px; margin-top: 20px; border: none; border-radius: 5px; cursor: pointer;">Add to Bag</button>
78
+ </div>
79
+ """
80
+ return popup_content
81
+
82
  # Gradio app definition
83
  def app():
84
  with gr.Blocks(title="Dynamic Menu with Filters") as demo:
 
94
  # Output area for menu items
95
  menu_output = gr.HTML(value=filter_menu("All"))
96
 
97
+ # Popup area
98
+ popup_output = gr.HTML()
99
+
100
  # Define interactivity
101
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
102
+ menu_output.change(generate_popup, inputs=[], outputs=[popup_output])
103
 
104
  # Layout
105
  gr.Row([selected_preference])
106
  gr.Row(menu_output)
107
+ gr.Row(popup_output)
108
 
109
  return demo
110