Chuyển tới nội dung chính

Demo UI

Mục đích​

Demo UI dùng để trình diễn vòng lặp GDP (Guideline-to-Prompt) từ đầu đến cuối trên một màn hình: lấy chunk từ guideline nuImages, sinh và kiểm tra labels.yaml, chạy SAM 3 và chấm IoU, rồi nhập feedback và chạy vòng sau cho tới khi selectBest chọn prompt tốt nhất. Đây là demo showcase, không phải công cụ annotation chính thức. Thiết kế hệ thống phía sau nằm ở Hệ thống GDP và Design và contract GDP.

Công nghệ​

Bản chạy là React + Vite (Bun) và FastAPI (gdp-api), local ở http://127.0.0.1:5173 và http://127.0.0.1:8000. Wireframe cũ vẽ Gradio (localhost:7860); đó là bản phác, không phải app đang chạy.

UI chỉ gọi các interface đã chốt: Prompt Engine (/gdp-design/prompt-engine) và Eval Runner (/gdp-design/eval-runner). UI không tự tính IoU hay tự viết prompt. Dữ liệu đi giữa các tab là ba data contract trong Contracts, cộng bảng điểm validation/test của bước Select best.

Chạy demo​

Wireframe trên trang này mô tả Gradio. Bản chạy được là ứng dụng React + Vite (package manager Bun), với một lớp FastAPI mỏng. UI không tự tính IoU và không tự viết prompt; nó gọi Retriever, PromptGenerator, Guardrails, Segmenter, Evaluator và Orchestrator đã có.

# backend (từ thư mục gốc của repo)
python -m pip install -e "source-tool/gdp[dev,api]"
GDP_API_MODE=offline gdp-api # http://127.0.0.1:8000

# frontend
cd source-tool/gdp-ui && bun install && bun dev # http://localhost:5173

GDP_API_MODE=live dùng RagRetriever, llm_from_env (kể cả GDP_LLM_PROVIDER=modal) và SAM 3. Biến môi trường nằm ở mục Modal trong source-tool/gdp/README.md.

Trong source-tool/gdp-ui: bun run build và bun run test. Lệnh test là bun run test (Vitest). Nếu thiếu gold mask, tab Eval hiện banner và không ghi EvalReport.

Dataset trong header​

Dropdown Dataset có ba lựa chọn: Demo fixture, nuImages mini, Final test. Mục nào không có ảnh hoặc splits.json thì bị disable. Đổi dataset hỏi confirm rồi xóa state của session (prompt, EvalReport, vòng lặp). GET /api/datasets trả name, root, image count, opt count và gold có đủ cho tập opt hay không. POST /api/dataset với {name} dựng lại catalog, split và thư mục gold.

Mặc định offline vẫn là Demo fixture (8 ảnh synthetic trong source-tool/gdp/fixtures/demo). GDP_DATASET chọn dataset khi không chỉ định tên, giống CLI. GDP_API_DATASET và GDP_API_GOLD thắng khi được set: API không cho đổi sang dataset khác, và gold lấy từ GDP_API_GOLD (hoặc GDP_API_GOLD_DIR) thay vì <dataset>/gold.

Dòng dưới tiêu đề là số ảnh opt / held-out theo case, đọc từ splits.json (Demo fixture không có split nên held-out là 0). Split scored của bộ review là opt, validation và test, không phải ba bản opt. held_out = validation + test. unscored là ảnh other. Vòng tối ưu chỉ chấm opt. Select best chấm validation. test được chấm đúng một lần.

nuImages mini​

source-tool/dataset/nuimages_mini/ có img/, gold/, manifest.json, splits.json. 50 keyframe, 36 ảnh có car, 26 ảnh opt, seed 24. Đếm theo case (opt / held-out): far_small 4 / 1, blur_rain 1 / 1, van_truck 21 / 1, other 0 / 21. blur_rain chỉ có 2 ảnh và far_small chỉ có 5 ảnh trên cả tập, nên IoU trên mini là minh họa cho demo, không phải kết quả đánh giá.

Khi chọn nuImages mini, header có badge: nuImages mini: demo only, scores are illustrative. Offline thêm predictions: simulated. Cùng câu đó nằm ở đầu tab Eval. Mỗi EvalReport ghi dataset, đường dẫn splits.json (split) và predictions.

Offline không có mask SAM 3 đã ghi cho các ảnh này. Segmenter giả lập nằm ở gdp.testing.simulate (không nằm trong class chấm điểm hay SAM 3): từ gold mask, seed 24, erode / dilate / shift / bỏ component nhỏ. Chất lượng tăng từ v1 lên v3; một vài ảnh vẫn dưới IoU 0.5. Held-out không được đưa vào vòng chấm.

# offline, không gọi Modal
GDP_API_MODE=offline GDP_API_DATASET=nuimages_mini gdp-api

# live: RagRetriever, LLM Modal, sam3_segmenter_from_env trên ảnh opt,
# GoldMaskLoader đọc source-tool/dataset/nuimages_mini/gold
GDP_API_MODE=live GDP_API_DATASET=nuimages_mini gdp-api

Số chính thức lấy từ CLI (gdp-eval, gdp-loop) trên tập nuImages v1.0-val, không lấy từ demo này. Mini không đủ cho far_small và blur_rain; cách dựng val nằm ở source-tool/gdp/README.md.

Run the live demo​

Live mode calls the real stack: doc-rag over the nuImages annotator instructions, Qwen on Modal (GDP_LLM_PROVIDER=modal), and SAM 3 text on Modal. IoU uses the gold masks in source-tool/dataset/nuimages_mini/gold. A live EvalReport is tagged dataset: nuimages_mini and predictions: sam3. sam3 means the masks came from the SAM 3 endpoint. Offline nuImages mini is predictions: simulated and does not call Modal.

The gdp package does not read a .env file. Export variables, or source source-tool/scripts/live_env.example.sh. That script exports the non-secret settings and checks that MODAL_PROXY_KEY, MODAL_PROXY_SECRET, and HF_TOKEN are already set. It does not print their values. Do not commit a .env. Copy placeholders from source-tool/gdp/.env.example.

Prerequisites​

  • Python 3.10+ and Bun.
  • python -m pip install -e "source-tool/gdp[dev,api]".
  • CPU doc-rag, from source-tool/doc-rag: install torch==2.9.1 from the PyTorch CPU index, then pip install -e source-tool/doc-rag. The embedding model is Qwen/Qwen3-Embedding-0.6B (DOC_RAG_MODEL). HF_TOKEN may be required for the download.
  • cd source-tool/gdp-ui && bun install.
  • Modal proxy auth already in the environment (Modal-Key / Modal-Secret). The same pair is sent by sam3_segmenter_from_env and modal_llm_from_env.

Guideline index​

nuImages does not publish a guideline PDF. The official instructions are Markdown, docs/instructions_nuimages.md in the nuScenes devkit, which the nuImages site points to through that devkit. This repo vendors that file at source-tool/gdp/knowledge/instructions_nuimages.md. doc-rag index only accepts a PDF, so render one and index it (the index stays in DOC_RAG_HOME, outside the repo):

python3 source-tool/scripts/render_guideline_pdf.py
doc-rag index --id nuimages --pdf ~/.doc-rag/sources/nuimages-annotator-instructions.pdf

Cold start​

The first request to each Modal app can take several minutes while the container starts and the weights download. Run the warm-up before the demo, and use the long timeouts already set (GDP_LLM_TIMEOUT_SEC=180, SAM3_TIMEOUT_SEC=170). warmup_modal.sh retries SAM 3 GET health and one short LLM completion with backoff.

On demo day, set min_containers=1 (it is 0 today) on Sam3Service in source-tool/gpu_integrate/modal/sam3_app.py and on serve in source-tool/gdp/modal/qwen_vllm_app.py, then modal deploy those files. That keeps one container up so the first click is not a cold start. Leave it at 0 when nobody is presenting; idle GPUs are billed.

Commands​

From the repo root, with the three secrets already exported:

source source-tool/scripts/live_env.example.sh
bash source-tool/scripts/warmup_modal.sh
bash source-tool/scripts/run_live_demo.sh

run_live_demo.sh inits the doc-rag submodule, resplits a review-set path (GDP_REVIEW_SET, or GDP_API_DATASET when that value is a directory outside nuImages mini / final test), warms Modal, indexes the guideline if doc-rag info --id nuimages fails, then starts gdp-api at http://127.0.0.1:8000 and the UI at http://127.0.0.1:5173. GDP_API_DATASET defaults to nuimages_mini and can be overridden before sourcing live_env.example.sh. A resplit exit code of 1 is the blur_rain shortfall warning; splits.json is still written.

Open the UI, choose doc id nuimages, set k = 4 and max rounds (3–5, demo dùng 5), Retrieve, then Run SAM3. Run SAM3 gửi đúng prompt đang hiện và chấm opt một lần. Vòng tối ưu dừng sớm khi IoU không tăng (early_stop_patience = 1). Sau khi vòng kết thúc, tab Select best chấm mọi candidate cộng baseline passenger car trên validation, rồi chấm prompt thắng và baseline trên test đúng một lần.

Bộ review của Tiến, sau gdp-data resplit --opt-size 30 --validation-size 30, có opt 30, validation 30, test 87, unscored 63. nuImages mini (26 ảnh opt) chỉ là fixture minh họa.

Component checks, without the UI:

python3 source-tool/scripts/live_smoke.py
python3 source-tool/scripts/live_api_loop.py

live_api_loop.py expects gdp-api to be up. It posts /api/loop/start and, when a round is waiting on reviewer notes, posts error_text so the loop can continue. Those notes are a stand-in for Chi. The prompts, masks, and IoU are not simulated. The loop stops before max_rounds when a new round does not raise IoU (early_stop_patience is 1). A live run can finish at v2 with reason no improvement.

pytest source-tool/gdp -q does not call Modal. Tests marked live are skipped unless you pass -m live.

Offline and live​

OfflineLive
RetrieverKeyword snippets from the bundled Markdowndoc-rag query on the indexed guideline
PromptFakeLlmQwen on Modal
SAM 3Recorded PNGs, or predictions: simulated on nuImages minisam3_segmenter_from_env
Report tagrecorded or simulatedpredictions: sam3
NetworkNoneModal, and Hugging Face the first time the embedding model is downloaded

Troubleshooting​

  • 401 from Modal. Proxy auth rejected the request. Confirm MODAL_PROXY_KEY and MODAL_PROXY_SECRET are exported in the same shell that starts gdp-api. The client sends them as Modal-Key and Modal-Secret. A 401 body is not a bad prompt.
  • LLM process exits during cold start. vLLM's flashinfer sampler tries to JIT-compile and fails with Could not find nvcc because the image has no CUDA toolkit. source-tool/gdp/modal/qwen_vllm_app.py sets VLLM_USE_FLASHINFER_SAMPLER=0 on the image. Redeploy that file after pulling the change. warmup_modal.sh polls GET /v1/models with a 60s cap per request and backoff, for about 10 minutes, instead of holding one connection open.
  • Timeouts. A cold container can outlive SAM3_TIMEOUT_SEC or GDP_LLM_TIMEOUT_SEC. Re-run warmup_modal.sh and wait until both lines print a success status. Then rerun the demo while the container is still up (scaledown_window is 300 seconds of idle time).
  • Missing index. doc-rag query exits non-zero with an unknown id. Render the PDF and doc-rag index --id nuimages. Live upload in the UI does not build this index.
  • No Hugging Face access to facebook/sam3. SAM 3 weights load inside Modal, not on the laptop. The Modal secret named huggingface (HF_TOKEN) must be accepted by the gated facebook/sam3 repo. A local HF_TOKEN is still used to download Qwen/Qwen3-Embedding-0.6B for doc-rag. If the embedding download returns 401 or 403, the token cannot read that model.

Wireframe tổng thể​

Wireframe demo UI Gradio: 4 tab Guideline, Prompt, Eval, Feedback &amp; loop

Mở sơ đồ trên Excalidraw

Tiêu đề trên canvas ghi "GDP Demo UI – Gradio wireframe v1", kèm dòng mô tả: low-fi wireframe, 4 Gradio tab, chạy đúng vòng lặp GDP; flow Guideline → labels.yaml → EvalReport → Feedback → next round. File trong docs là bản export v2 sau khi Bằng chỉnh.

User flow qua 4 tab​

BướcTabNgười dùng làm gìKết quả
1GuidelineUpload / chọn guideline nuImages, chọn class car, bấm RetrieveGuideline text với các đoạn được highlight, danh sách top-K chunk kèm score
2PromptXem labels.yaml do LLM sinh, xem kết quả Guardrails, bấm Regenerate hoặc Run SAM3Một LabelsSpec đã qua schema
3EvalXem lưới mask SAM 3 so với gold mask, IoU total, IoU by case; bấm Export EvalReportMột EvalReport
4Feedback & loopReviewer (Chi) viết error_text cho ảnh IoU thấp, bấm Save Feedback / Run next round; xem tree search, IoU per round, before/afterMột Feedback; vòng sau quay lại tab Prompt
5Select bestChấm P1..Pn và baseline passenger car trên validation, rồi chấm prompt tốt nhất và baseline trên test một lầnBảng IoU validation và kết quả test

Mũi tên đứt nét màu cam dưới wireframe ghi "next round: Feedback + RAG -> P(n+1)": từ tab 4 quay lại tab 2.

Contract và màn hình​

ContractMũi tên trên wireframeTạo ở tabHiển thị / dùng ở tab
labels.yaml (LabelsSpec)Guideline → PromptPrompt (sau Guardrails)Prompt (code view); Eval (đầu vào SAM 3)
EvalReportPrompt → EvalEvalEval (IoU total, bar chart, viền đỏ ảnh IoU thấp); Feedback (ảnh cần review)
FeedbackEval → Feedback & loopFeedback & loopFeedback (textbox error_text); vòng sau (RAG query và PromptGenerator)

Trên wireframe, các mũi tên contract đi giữa các khung màn hình theo thứ tự trên. Ý nghĩa: mỗi tab nhận contract của tab trước.

Lưu ý về số liệu​

Mọi giá trị trên wireframe (score chunk, IoU, tên ảnh img_01…img_08, prompt mẫu, error_text, cây P0–P3) là minh họa, không phải kết quả chạy thật.

Các trang con​