nagasurendra commited on
Commit
3c97bed
·
verified ·
1 Parent(s): 8ac09ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -39
app.py CHANGED
@@ -28,15 +28,15 @@ def filter_menu(preference):
28
  html_content = ""
29
  for _, item in filtered_data.iterrows():
30
  html_content += f"""
31
- <div class="menu-card">
32
- <div class="menu-card-details">
33
- <h3>{item['Dish Name']}</h3>
34
- <p>${item['Price ($)']}</p>
35
- <p>{item['Description']}</p>
36
  </div>
37
- <div class="menu-card-actions">
38
- <img src="{item['Image URL']}" alt="{item['Dish Name']}" class="menu-card-image">
39
- <button onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')" class="add-button">Add</button>
40
  </div>
41
  </div>
42
  """
@@ -44,7 +44,7 @@ def filter_menu(preference):
44
 
45
  # Gradio app definition
46
  def app():
47
- with gr.Blocks(css="style.css") as demo:
48
  gr.Markdown("## Dynamic Menu with Preferences")
49
 
50
  # Radio button for selecting preference
@@ -57,37 +57,40 @@ def app():
57
  # Output area for menu items
58
  menu_output = gr.HTML(value=filter_menu("All"))
59
 
60
- # Modal window (hidden by default)
61
  modal_window = gr.HTML("""
62
- <div id="modal" class="modal">
63
- <div class="modal-content">
64
- <span class="close-button" onclick="closeModal()">&times;</span>
65
- <img id="modal-image" class="modal-image" />
66
- <h2 id="modal-name"></h2>
67
- <p id="modal-description"></p>
68
- <p id="modal-price"></p>
69
- <label for="spice-level">Choose Spice Level:</label>
70
- <select id="spice-level">
71
- <option value="Mild">Mild</option>
72
- <option value="Medium">Medium</option>
73
- <option value="Spicy">Spicy</option>
74
- </select>
75
- <label for="quantity">Quantity:</label>
76
- <input type="number" id="quantity" value="1" min="1" />
77
- <textarea id="special-instructions" placeholder="Add special instructions here..."></textarea>
78
- <button class="modal-add-button">Add to Cart</button>
79
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  </div>
81
  <script>
82
  function openModal(name, image, description, price) {
83
- document.getElementById("modal").style.display = "block";
84
- document.getElementById("modal-image").src = image;
85
- document.getElementById("modal-name").innerText = name;
86
- document.getElementById("modal-description").innerText = description;
87
- document.getElementById("modal-price").innerText = price;
88
  }
89
  function closeModal() {
90
- document.getElementById("modal").style.display = "none";
91
  }
92
  </script>
93
  """)
@@ -96,12 +99,9 @@ def app():
96
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
97
 
98
  # Layout
99
- with gr.Row():
100
- selected_preference
101
- with gr.Row():
102
- menu_output
103
- with gr.Row():
104
- modal_window
105
 
106
  return demo
107
 
 
28
  html_content = ""
29
  for _, item in filtered_data.iterrows():
30
  html_content += f"""
31
+ <div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
32
+ <div style="flex: 1; margin-right: 15px;">
33
+ <h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
34
+ <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
35
+ <p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
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;" onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')">Add</button>
40
  </div>
41
  </div>
42
  """
 
44
 
45
  # Gradio app definition
46
  def app():
47
+ with gr.Blocks() as demo:
48
  gr.Markdown("## Dynamic Menu with Preferences")
49
 
50
  # Radio button for selecting preference
 
57
  # Output area for menu items
58
  menu_output = gr.HTML(value=filter_menu("All"))
59
 
60
+ # Modal window
61
  modal_window = gr.HTML("""
62
+ <div id="modal" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 50%; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
63
+ <div style="text-align: right;">
64
+ <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  </div>
66
+ <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
67
+ <h2 id="modal-name"></h2>
68
+ <p id="modal-description"></p>
69
+ <p id="modal-price"></p>
70
+ <label for="spice-level">Choose Spice Level:</label>
71
+ <select id="spice-level">
72
+ <option value="Mild">Mild</option>
73
+ <option value="Medium">Medium</option>
74
+ <option value="Spicy">Spicy</option>
75
+ </select>
76
+ <br><br>
77
+ <label for="quantity">Quantity:</label>
78
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
79
+ <br><br>
80
+ <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
81
+ <br><br>
82
+ <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;">Add to Cart</button>
83
  </div>
84
  <script>
85
  function openModal(name, image, description, price) {
86
+ document.getElementById('modal').style.display = 'block';
87
+ document.getElementById('modal-image').src = image;
88
+ document.getElementById('modal-name').innerText = name;
89
+ document.getElementById('modal-description').innerText = description;
90
+ document.getElementById('modal-price').innerText = price;
91
  }
92
  function closeModal() {
93
+ document.getElementById('modal').style.display = 'none';
94
  }
95
  </script>
96
  """)
 
99
  selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
100
 
101
  # Layout
102
+ gr.Row([selected_preference])
103
+ gr.Row(menu_output)
104
+ gr.Row(modal_window)
 
 
 
105
 
106
  return demo
107