Rammohan0504 commited on
Commit
57dc350
·
verified ·
1 Parent(s): 93517e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -69,6 +69,7 @@ def filter_dishes(category):
69
  return [dish for dish in menu_data if dish["category"] == category]
70
 
71
  # Function to generate dish cards
 
72
  def display_dishes(category):
73
  filtered_dishes = filter_dishes(category)
74
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
@@ -76,11 +77,13 @@ def display_dishes(category):
76
  html_content += f"""
77
  <div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
78
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
79
- background-color: #f9f9f9; cursor: pointer;'
80
- onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
81
  <div style='flex: 1; margin-right: 20px;'>
82
  <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
83
  <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
 
 
 
84
  </div>
85
  <img src='{dish['image']}' alt='{dish['name']}'
86
  style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
@@ -89,27 +92,17 @@ def display_dishes(category):
89
  html_content += "</div>"
90
  return html_content
91
 
92
- # Main Gradio App
93
- with gr.Blocks() as demo:
94
- gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
95
-
96
- # Buttons for category selection
97
- with gr.Row():
98
- btn_all = gr.Button("ALL")
99
- btn_vegan = gr.Button("VEGAN")
100
- btn_halal = gr.Button("HALAL")
101
-
102
- # Dish display
103
- dish_display = gr.HTML(value=display_dishes("ALL"))
104
-
105
- # JavaScript for managing the pop-up
106
- gr.HTML("""
107
- <div id="popup" style="display: none; position: fixed; left: 50%; justify-content: center; align-items: center; transform: translate(-50%, 100%)
108
- background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
109
- z-index: 1000; text-align: center; width: 300px;">
110
  <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
111
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
112
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
 
 
 
113
  <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
114
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
115
  </div>
@@ -127,8 +120,11 @@ with gr.Blocks() as demo:
127
  function closePopup() {
128
  document.getElementById('popup').style.display = 'none';
129
  }
 
 
 
130
  </script>
131
- """)
132
 
133
  # Button click events
134
  btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
 
69
  return [dish for dish in menu_data if dish["category"] == category]
70
 
71
  # Function to generate dish cards
72
+ # Function to generate dish cards with "Add" button
73
  def display_dishes(category):
74
  filtered_dishes = filter_dishes(category)
75
  html_content = "<div style='display: flex; flex-direction: column; align-items: center; width: 100%;'>"
 
77
  html_content += f"""
78
  <div style='margin: 10px; display: flex; align-items: center; justify-content: space-between;
79
  width: 80%; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
80
+ background-color: #f9f9f9;'>
 
81
  <div style='flex: 1; margin-right: 20px;'>
82
  <h4 style='font-size: 18px; color: #444; margin: 0;'>{dish['name']}</h4>
83
  <p style='font-size: 14px; color: #666; margin: 5px 0;'>{dish['description']}</p>
84
+ <button onclick="addToCart('{dish['name']}')"
85
+ style="padding: 5px 10px; background-color: #28a745; color: white; border: none;
86
+ border-radius: 5px; cursor: pointer;">Add</button>
87
  </div>
88
  <img src='{dish['image']}' alt='{dish['name']}'
89
  style='width: 120px; height: 80px; object-fit: cover; border-radius: 10px;'>
 
92
  html_content += "</div>"
93
  return html_content
94
 
95
+ # JavaScript for managing the pop-up and "Add" button
96
+ gr.HTML("""
97
+ <div id="popup" style="display: none; position: fixed; left: 50%; justify-content: center; align-items: center;
98
+ transform: translate(-50%, 100%) background-color: white; padding: 20px; border-radius: 10px;
99
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
101
  <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
102
  <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
103
+ <button onclick="addToCart(document.getElementById('popup-title').textContent)"
104
+ style="margin-top: 10px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
105
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
106
  <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
107
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
108
  </div>
 
120
  function closePopup() {
121
  document.getElementById('popup').style.display = 'none';
122
  }
123
+ function addToCart(dishName) {
124
+ alert(dishName + " has been added to the cart!");
125
+ }
126
  </script>
127
+ """)
128
 
129
  # Button click events
130
  btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)