Rammohan0504 commited on
Commit
3b11719
·
verified ·
1 Parent(s): 3cfb0b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -40
app.py CHANGED
@@ -71,51 +71,56 @@ with gr.Blocks() as demo:
71
  dish_display = gr.HTML(value=display_dishes("ALL"))
72
 
73
  # JavaScript for managing the pop-up
74
- gr.HTML(f"""
75
- <div id=\"popup\" style=\"display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
76
- background-color: white; padding: 20px; border-radius: 10px;
77
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;\">
78
- <img id=\"popup-image\" src=\"\" alt=\"\" style=\"width: 100%; height: auto; border-radius: 10px;\">
79
- <h2 id=\"popup-title\" style=\"margin-top: 20px; color: #444;\"></h2>
80
- <p id=\"popup-description\" style=\"margin-top: 10px; font-size: 16px; color: #666;\"></p>
81
- <p id=\"popup-price\" style=\"margin-top: 10px; font-size: 16px; color: #444;\"></p>
82
-
83
- <h4 style=\"text-align: left; margin-top: 20px;\">Choose a spice level</h4>
84
- <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
85
- """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"radio\" name=\"spice\" value=\"{spice}\" style=\"margin-right: 5px;\">{spice}</label>' for spice in spice_levels]) + """
86
- </div>
87
 
88
- <h4 style=\"text-align: left; margin-top: 20px;\">Choose Extras</h4>
89
- <div style=\"display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;\">
90
- """ + """".join([f'<label style=\"margin-right: 10px; display: block;\"><input type=\"checkbox\" name=\"extras\" value=\"{extra["name"]}\" style=\"margin-right: 5px;\">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
91
- </div>
 
 
 
92
 
93
- <button onclick=\"addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)\"
94
- style=\"margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
95
- border-radius: 5px; cursor: pointer;\">Add to Cart</button>
96
- <button onclick=\"closePopup()\" style=\"margin-top: 20px; padding: 10px 20px; background-color: #28a745;
97
- color: white; border: none; border-radius: 5px; cursor: pointer;\">Close</button>
 
98
  </div>
99
- <script>
100
- function showPopup(image, title, description, price) {
101
- document.getElementById('popup-image').src = image;
102
- document.getElementById('popup-title').textContent = title;
103
- document.getElementById('popup-description').textContent = description;
104
- document.getElementById('popup-price').textContent = "Price: " + price;
105
 
106
- // Display the popup
107
- document.getElementById('popup').style.display = 'block';
108
- }
109
- function closePopup() {
110
- document.getElementById('popup').style.display = 'none';
111
- }
112
- function addToCart(dishName, spiceLevel) {
113
- const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
114
- alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
115
- }
116
- </script>
117
- """)
118
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  # Button click events
120
  btn_all.click(
121
  lambda: gr.update(value=display_dishes("ALL")),
 
71
  dish_display = gr.HTML(value=display_dishes("ALL"))
72
 
73
  # JavaScript for managing the pop-up
74
+ gr.HTML("""
75
+ <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
76
+ background-color: white; padding: 20px; border-radius: 10px;
77
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
78
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
79
+ <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
80
+ <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
81
+ <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
 
 
 
 
 
82
 
83
+ <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
84
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
85
+ """ + "".join(
86
+ [f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>'
87
+ for spice in spice_levels]
88
+ ) + """
89
+ </div>
90
 
91
+ <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
92
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
93
+ """ + "".join(
94
+ [f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>'
95
+ for extra in extras]
96
+ ) + """
97
  </div>
 
 
 
 
 
 
98
 
99
+ <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
100
+ style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
101
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
102
+ <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
103
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
104
+ </div>
105
+ <script>
106
+ function showPopup(image, title, description, price) {
107
+ document.getElementById('popup-image').src = image;
108
+ document.getElementById('popup-title').textContent = title;
109
+ document.getElementById('popup-description').textContent = description;
110
+ document.getElementById('popup-price').textContent = "Price: " + price;
111
 
112
+ // Display the popup
113
+ document.getElementById('popup').style.display = 'block';
114
+ }
115
+ function closePopup() {
116
+ document.getElementById('popup').style.display = 'none';
117
+ }
118
+ function addToCart(dishName, spiceLevel) {
119
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
120
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
121
+ }
122
+ </script>
123
+ """)
124
  # Button click events
125
  btn_all.click(
126
  lambda: gr.update(value=display_dishes("ALL")),