schillerCFK commited on
Commit
7a23f72
·
verified ·
1 Parent(s): 2c4a428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -115,13 +115,17 @@ def get_revenue():
115
  total = sum(order["總價"] for order in orders_db)
116
  return f"### 💰 目前總營收:NT$ {total}"
117
 
118
- # 使用 *args 強制接收所有參數,避免 Gradio 在不同設備上解析錯誤
119
- def add_order(*args):
 
 
 
 
120
  try:
121
  # 安全地轉換姓名與備註 (避免 NoneType 錯誤)
122
- customer_name = str(args[0]) if args[0] else ""
123
- notes = str(args[1]) if args[1] else ""
124
- quantities = args[2:]
125
 
126
  if not customer_name.strip():
127
  return "❌ 錯誤:請輸入顧客姓名", get_orders_df(), get_revenue()
@@ -260,12 +264,13 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統", css=cus
260
  logout_btn.click(fn=logout, inputs=[], outputs=[login_pane, overview_pane, login_status, admin_pwd])
261
  clear_btn.click(fn=clear_orders, inputs=[], outputs=[status_msg, orders_table, revenue_display])
262
  github_btn.click(fn=backup_and_push_to_github, inputs=[], outputs=[github_log_output])
263
- refresh_btn.click(fn=lambda: (get_orders_df(), get_revenue()), inputs=[], outputs=[orders_table, revenue_display])
264
 
265
  # ----------------------------
266
  # 🚀 啟動伺服器
267
  # ----------------------------
268
- app = gr.mount_gradio_app(custom_api, demo_ui, path="/")
 
269
 
270
  if __name__ == "__main__":
271
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
115
  total = sum(order["總價"] for order in orders_db)
116
  return f"### 💰 目前總營收:NT$ {total}"
117
 
118
+ def refresh_data():
119
+ """獨立的重新整理函式,避免使用 lambda 導致解析失敗"""
120
+ return get_orders_df(), get_revenue()
121
+
122
+ # 取消 *args,改用明確的 7 個參數,徹底解決 Gradio 參數解析失敗導致的當機 (Silent Error)
123
+ def add_order(customer_name, notes, q0, q1, q2, q3, q4):
124
  try:
125
  # 安全地轉換姓名與備註 (避免 NoneType 錯誤)
126
+ customer_name = str(customer_name) if customer_name else ""
127
+ notes = str(notes) if notes else ""
128
+ quantities = [q0, q1, q2, q3, q4]
129
 
130
  if not customer_name.strip():
131
  return "❌ 錯誤:請輸入顧客姓名", get_orders_df(), get_revenue()
 
264
  logout_btn.click(fn=logout, inputs=[], outputs=[login_pane, overview_pane, login_status, admin_pwd])
265
  clear_btn.click(fn=clear_orders, inputs=[], outputs=[status_msg, orders_table, revenue_display])
266
  github_btn.click(fn=backup_and_push_to_github, inputs=[], outputs=[github_log_output])
267
+ refresh_btn.click(fn=refresh_data, inputs=[], outputs=[orders_table, revenue_display])
268
 
269
  # ----------------------------
270
  # 🚀 啟動伺服器
271
  # ----------------------------
272
+ # 加上 .queue() 確保 Hugging Face Spaces 的 WebSocket 長連線不會被阻擋
273
+ app = gr.mount_gradio_app(custom_api, demo_ui.queue(), path="/")
274
 
275
  if __name__ == "__main__":
276
  uvicorn.run(app, host="0.0.0.0", port=7860)