Spaces:
Runtime error
Runtime error
Update app.py (#1)
Browse files- Update app.py (dcc0d05869b3b5cfb3cd2ca2d902d0e90fe02781)
Co-authored-by: Siyuan Wan <Wanswan@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -236,66 +236,8 @@ with gr.Blocks() as demo:
|
|
| 236 |
f"**{name}**\n\n{desc}\n\n{price_html}",
|
| 237 |
show_label=False,
|
| 238 |
)
|
| 239 |
-
with gr.Column(scale=2):
|
| 240 |
-
add_btn = gr.Button(value="")
|
| 241 |
-
button_refs.append((item, add_btn))
|
| 242 |
-
gr.Markdown("<br><br>")
|
| 243 |
-
gr.Markdown("### Your Cart")
|
| 244 |
-
cart_table = gr.DataFrame(
|
| 245 |
-
pd.DataFrame(columns=["Dish", "Unit Price", "Quantity"]),
|
| 246 |
-
headers=["Dish", "Unit Price", "Quantity"],
|
| 247 |
-
interactive=True,
|
| 248 |
-
label="",
|
| 249 |
-
)
|
| 250 |
-
total_display = gr.Markdown("**Total: € 0.00**")
|
| 251 |
-
note_input = gr.Textbox(label="Other Note", placeholder="Additional notes or requests…", lines=2)
|
| 252 |
-
decision_output = gr.Markdown(visible=False)
|
| 253 |
-
confirm_button = gr.Button("✅ I have made my decision")
|
| 254 |
-
change_button = gr.Button("🔄 Wait, I want to make change", visible=False)
|
| 255 |
-
|
| 256 |
-
for _item, _btn in button_refs:
|
| 257 |
-
def _on_add(cart_state, item=_item):
|
| 258 |
-
df, total, new_cart = add_item_simple(item, cart_state)
|
| 259 |
-
return df, total, new_cart
|
| 260 |
-
_btn.click(
|
| 261 |
-
_on_add,
|
| 262 |
-
inputs=[cart_state],
|
| 263 |
-
outputs=[cart_table, total_display, cart_state],
|
| 264 |
-
)
|
| 265 |
-
|
| 266 |
-
def _on_table_edit(df, cart_state):
|
| 267 |
-
df_new, total, new_cart = update_cart_from_table(df, cart_state)
|
| 268 |
-
return df_new, total, new_cart
|
| 269 |
-
cart_table.change(
|
| 270 |
-
_on_table_edit,
|
| 271 |
-
inputs=[cart_table, cart_state],
|
| 272 |
-
outputs=[cart_table, total_display, cart_state],
|
| 273 |
-
)
|
| 274 |
|
| 275 |
-
def _confirm_wrapper(cart_df, note):
|
| 276 |
-
message_update = finalize_order(cart_df, note)
|
| 277 |
-
return (
|
| 278 |
-
message_update,
|
| 279 |
-
gr.Button.update(visible=False),
|
| 280 |
-
gr.Button.update(visible=True),
|
| 281 |
-
)
|
| 282 |
-
confirm_button.click(
|
| 283 |
-
_confirm_wrapper,
|
| 284 |
-
inputs=[cart_table, note_input],
|
| 285 |
-
outputs=[decision_output, confirm_button, change_button],
|
| 286 |
-
)
|
| 287 |
|
| 288 |
-
def _change_wrapper():
|
| 289 |
-
return (
|
| 290 |
-
gr.Markdown.update(visible=False, value=""),
|
| 291 |
-
gr.Button.update(visible=True),
|
| 292 |
-
gr.Button.update(visible=False),
|
| 293 |
-
)
|
| 294 |
-
change_button.click(
|
| 295 |
-
_change_wrapper,
|
| 296 |
-
inputs=[],
|
| 297 |
-
outputs=[decision_output, confirm_button, change_button],
|
| 298 |
-
)
|
| 299 |
|
| 300 |
if __name__ == "__main__":
|
| 301 |
demo.launch()
|
|
|
|
| 236 |
f"**{name}**\n\n{desc}\n\n{price_html}",
|
| 237 |
show_label=False,
|
| 238 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
if __name__ == "__main__":
|
| 243 |
demo.launch()
|