Spaces:
Sleeping
Sleeping
feat(manual): town-level examples (numeric / categorical)
Browse filesSample data for 臺北市 + 新北市 (41 districts, made-up values) that switches
the tab to town level; PPTX export then yields two county slides.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1157 unmodified lines1158115911601161116211631164116511661167116811691170117111721173117411751176117711781179829 unmodified lines2009201020111996199720122013201420152016201720182019156 unmodified lines2176217721782179218021812182218321841157 unmodified lines store.update(MANUAL_EXAMPLES[kind]) return store, gr.update(value="縣市"), _scope_visibility("縣市"), manual_table("縣市", MANUAL_NATIONAL, store)
TOWN_EXAMPLE_COUNTIES = ["臺北市", "新北市"]
def load_town_example(kind: str, store): """ 鄉鎮層級的示範資料(臺北市+新北市共 41 區,數值為示範用的假資料,不是真實統計)。 切到鄉鎮市區、範圍選新北市;匯出 PPTX 會得到臺北市、新北市兩頁,可用來預覽版面。 """ names = [n for c in TOWN_EXAMPLE_COUNTIES for n in manual_names("鄉鎮市區", c)] town_names = set(all_manual_names("鄉鎮市區")) store = {k: v for k, v in (store or {}).items() if k not in town_names} for i, name in enumerate(names): store[name] = f"{(i * 37) % 90 * 100 + 1000:,}" if kind == "數值" else ["甲類", "乙類", "丙類"][i % 3] scope = TOWN_EXAMPLE_COUNTIES[-1] return (store, gr.update(value="鄉鎮市區"), gr.update(value=scope, visible=True), manual_table("鄉鎮市區", scope, store))
def _resolver(level: str, scope: str): """把使用者輸入的名稱對到標準名稱:容許「台北市」、舊名、以及在單一縣市範圍內只寫鄉鎮名(板橋區)""" names = set(all_manual_names(level))829 unmodified lines ) btn_paste = gr.Button("⬆️ 匯入到表格", variant="secondary") with gr.Row(): btn_ex_cat = gr.Button("範例:分區", size="sm", variant="secondary") btn_ex_num = gr.Button("範例:數值", size="sm", variant="secondary") btn_ex_cat = gr.Button("縣市範例:分區", size="sm", variant="secondary") btn_ex_num = gr.Button("縣市範例:數值", size="sm", variant="secondary") with gr.Row(): btn_ex_town_num = gr.Button("鄉鎮範例:數值", size="sm", variant="secondary") btn_ex_town_cat = gr.Button("鄉鎮範例:分類", size="sm", variant="secondary") btn_clear = gr.Button("🗑️ 清空目前範圍", size="sm", variant="secondary") with gr.Column(scale=2, min_width=340): with gr.Row():156 unmodified lines for btn, kind in ((btn_ex_cat, "分區"), (btn_ex_num, "數值")): btn.click(fn=lambda store, k=kind: load_manual_example(k, store), inputs=manual_store, outputs=[manual_store, manual_level, manual_scope, manual_input_df]) for btn, kind in ((btn_ex_town_num, "數值"), (btn_ex_town_cat, "分類")): btn.click(fn=lambda store, k=kind: load_town_example(k, store), inputs=manual_store, outputs=[manual_store, manual_level, manual_scope, manual_input_df]) btn_clear.click(fn=clear_manual, inputs=[manual_level, manual_scope, manual_store], outputs=[manual_store, manual_input_df])
app.py+24-2