xiponn commited on
Commit
7d15bf1
·
verified ·
1 Parent(s): fe65043

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -569,19 +569,20 @@ with gr.Blocks(title="QuickDraw 風格資料蒐集 & 瀏覽") as demo:
569
  return (len(imgs) > 1) and (int(img_idx) < len(imgs) - 1)
570
 
571
  def render_ui(scene_idx, img_idx, count, collected, live):
572
- """統一把畫面更新邏輯集中在這裡,避免狀態亂掉。"""
573
  sc = current_scene(scene_idx)
574
  img_path = scene_image_path(scene_idx, img_idx)
575
 
576
- # prompt 文字:顯示關卡名 + 規則提示
577
- # 特例:關卡 3(貓咪 → 河)
 
 
 
 
578
  if sc.get("id") == 3:
579
  if int(img_idx) == 0:
580
- base_prompt = "⚠️ 一隻貓突然出現,把你嚇了一跳!"
581
  else:
582
- base_prompt = "前面被水擋住了,得想辦法渡河。"
583
- name = sc.get("name", "")
584
- mode = sc.get("mode", "")
585
 
586
  extra = ""
587
  if mode == "count_any":
@@ -595,11 +596,9 @@ with gr.Blocks(title="QuickDraw 風格資料蒐集 & 瀏覽") as demo:
595
 
596
  prompt = f"**關卡:** {name}\n\n{base_prompt}{extra}"
597
 
598
- # 控制按鈕可用性
599
  can_draw = in_draw_phase(scene_idx, img_idx)
600
  can_next = next_enabled(scene_idx, img_idx)
601
 
602
- # intro 的 Guess 一律 disabled;非 draw phase 的 Guess 也 disabled
603
  guess_upd = gr.update(interactive=bool(can_draw))
604
  next_upd = gr.update(interactive=bool(can_next))
605
  start_upd = gr.update(interactive=True)
 
569
  return (len(imgs) > 1) and (int(img_idx) < len(imgs) - 1)
570
 
571
  def render_ui(scene_idx, img_idx, count, collected, live):
 
572
  sc = current_scene(scene_idx)
573
  img_path = scene_image_path(scene_idx, img_idx)
574
 
575
+ # ✅ 一定要先給預設值,避免 UnboundLocalError
576
+ base_prompt = sc.get("prompt", "")
577
+ name = sc.get("name", "")
578
+ mode = sc.get("mode", "")
579
+
580
+ # ✅ 特例:關卡 3(貓咪→渡河)依圖片切換 prompt
581
  if sc.get("id") == 3:
582
  if int(img_idx) == 0:
583
+ base_prompt = "⚠️ 貓咪突然突襲!你嚇了一跳,先躲起來……(按 Next)"
584
  else:
585
+ base_prompt = "前面被水擋住了,得想辦法渡河。畫出能渡水的工具吧!"
 
 
586
 
587
  extra = ""
588
  if mode == "count_any":
 
596
 
597
  prompt = f"**關卡:** {name}\n\n{base_prompt}{extra}"
598
 
 
599
  can_draw = in_draw_phase(scene_idx, img_idx)
600
  can_next = next_enabled(scene_idx, img_idx)
601
 
 
602
  guess_upd = gr.update(interactive=bool(can_draw))
603
  next_upd = gr.update(interactive=bool(can_next))
604
  start_upd = gr.update(interactive=True)