Rammohan0504 commited on
Commit
3cf11d7
·
verified ·
1 Parent(s): 512fcf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -69,6 +69,7 @@ def display_dishes(category):
69
  html_content += f"""
70
  <div style='width: 220px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
71
  background-color: #f9f9f9; text-align: center; cursor: pointer;'
 
72
  onclick="showPopup(event, '{dish['image']}', '{dish['name']}', '{dish['description']}')">
73
  <img src='{dish['image']}' alt='{dish['name']}'
74
  style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
@@ -81,7 +82,7 @@ def display_dishes(category):
81
 
82
  # Main Gradio App
83
  with gr.Blocks() as demo:
84
- gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
85
 
86
  # Category Buttons
87
  with gr.Row():
@@ -92,9 +93,9 @@ with gr.Blocks() as demo:
92
  # Dish display area
93
  dish_display = gr.HTML(value=display_dishes("ALL"))
94
 
95
- # Pop-up HTML and JavaScript
96
  gr.HTML("""
97
- <div id="popup" style="display: none; position: static; justify-content:center;
98
  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;">
@@ -104,15 +105,25 @@ with gr.Blocks() as demo:
104
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
105
  </div>
106
  <script>
 
 
 
 
 
 
 
 
 
 
107
  function showPopup(event, image, title, description) {
108
  const popup = document.getElementById('popup');
109
  document.getElementById('popup-image').src = image;
110
  document.getElementById('popup-title').textContent = title;
111
  document.getElementById('popup-description').textContent = description;
112
 
113
- // Set the position of the popup based on the cursor's location
114
- popup.style.left = `${event.pageX}px`;
115
- popup.style.top = `${event.pageY}px`;
116
 
117
  popup.style.display = 'block';
118
  }
 
69
  html_content += f"""
70
  <div style='width: 220px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
71
  background-color: #f9f9f9; text-align: center; cursor: pointer;'
72
+ onmouseover="trackCursor(event)"
73
  onclick="showPopup(event, '{dish['image']}', '{dish['name']}', '{dish['description']}')">
74
  <img src='{dish['image']}' alt='{dish['name']}'
75
  style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
 
82
 
83
  # Main Gradio App
84
  with gr.Blocks() as demo:
85
+ gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Restaurant Menu 🍛</h1>")
86
 
87
  # Category Buttons
88
  with gr.Row():
 
93
  # Dish display area
94
  dish_display = gr.HTML(value=display_dishes("ALL"))
95
 
96
+ # Pop-up HTML and JavaScript with event listener
97
  gr.HTML("""
98
+ <div id="popup" style="display: none; position: absolute;
99
  background-color: white; padding: 20px; border-radius: 10px;
100
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
101
  <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
 
105
  color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
106
  </div>
107
  <script>
108
+ let cursorX = 0;
109
+ let cursorY = 0;
110
+
111
+ // Track the cursor's position
112
+ function trackCursor(event) {
113
+ cursorX = event.pageX;
114
+ cursorY = event.pageY;
115
+ }
116
+
117
+ // Show the pop-up at the tracked cursor position
118
  function showPopup(event, image, title, description) {
119
  const popup = document.getElementById('popup');
120
  document.getElementById('popup-image').src = image;
121
  document.getElementById('popup-title').textContent = title;
122
  document.getElementById('popup-description').textContent = description;
123
 
124
+ // Set the position of the popup based on the tracked cursor location
125
+ popup.style.left = `${cursorX}px`;
126
+ popup.style.top = `${cursorY}px`;
127
 
128
  popup.style.display = 'block';
129
  }