luispoveda93 commited on
Commit
44ebec0
·
verified ·
1 Parent(s): 488326a

Deterministic UI patch: short tab labels + explicit preset buttons

Browse files
Files changed (1) hide show
  1. phase5/screenshots/patch_ui.py +60 -0
phase5/screenshots/patch_ui.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, hashlib
2
+ from huggingface_hub import hf_hub_download, HfApi
3
+
4
+ REPO = "luispoveda93/pcap-kev-triage"
5
+ REPO_TYPE = "space"
6
+ p = hf_hub_download(REPO, "app.py", repo_type="space", force_download=True)
7
+ src = open(p, encoding="utf-8").read()
8
+ orig_sha = hashlib.sha256(src.encode()).hexdigest()
9
+ print("FETCHED app.py sha=%s bytes=%d" % (orig_sha, len(src)), flush=True)
10
+
11
+ def rep(old, new, tag):
12
+ global src
13
+ assert src.count(old) == 1, f"{tag}: expected 1 occurrence, found {src.count(old)}"
14
+ src = src.replace(old, new)
15
+ print(f"PATCHED {tag}", flush=True)
16
+
17
+ # Fix 1: short tab labels so all three tabs fit (and stay reachable) on a 390px phone
18
+ rep('with gr.Tab("\U0001f4e4 Analyze a capture"):',
19
+ 'with gr.Tab("\U0001f4e4 Analyze"):', "tab-analyze")
20
+ rep('with gr.Tab("\U0001f3af Playground"):',
21
+ 'with gr.Tab("\U0001f3af Playground"):'.replace("\U0001f3af Playground", "\U0001f3af Playground"),
22
+ "tab-playground-keep") # no-op guard: must exist exactly once
23
+
24
+ # Fix 2: explicit preset buttons replace gr.Examples (Gradio 6 rendered no clickable rows)
25
+ rep(""" gr.Examples(examples=PRESET_STATES, example_labels=PRESET_LABELS,
26
+ inputs=[state_box], outputs=[out_pg, out_pg_raw],
27
+ fn=run_state_battery, label="Locked-split presets (true label shown — never seen in training)")""",
28
+ """ gr.Markdown("**Locked-split presets** — true label shown; click to load the state and run the battery immediately (never seen in training).")
29
+ with gr.Row():
30
+ preset_btns = [gr.Button(lbl, size="sm") for lbl in PRESET_LABELS]""",
31
+ "preset-buttons")
32
+
33
+ # Fix 3: wire the preset buttons (load state + run battery in one click)
34
+ rep(""" btn.click(run_ui, inputs=[inp], outputs=[out_summary, out_table, out_detail, out_csv], api_name="analyze")
35
+ pg_btn.click(run_state_battery, inputs=[state_box], outputs=[out_pg, out_pg_raw], api_name="run_battery")""",
36
+ """ btn.click(run_ui, inputs=[inp], outputs=[out_summary, out_table, out_detail, out_csv], api_name="analyze")
37
+ pg_btn.click(run_state_battery, inputs=[state_box], outputs=[out_pg, out_pg_raw], api_name="run_battery")
38
+
39
+ for _i, _pb in enumerate(preset_btns):
40
+ def _preset_handler(idx=_i):
41
+ _st = LOCKED_EXAMPLES[idx]["state"]
42
+ _html, _raw = run_state_battery(_st)
43
+ return _st, _html, _raw
44
+ _pb.click(_preset_handler, inputs=None, outputs=[state_box, out_pg, out_pg_raw], api_name=f"preset_{_i + 1}")""",
45
+ "wire-preset-buttons")
46
+
47
+ # Fix 4: tablist must stay reachable on narrow screens (belt-and-braces with short labels)
48
+ rep('''CSS = """
49
+ #col-container { max-width: 1180px; margin: 0 auto; }
50
+ """''',
51
+ '''CSS = """
52
+ #col-container { max-width: 1180px; margin: 0 auto; }
53
+ #col-container [role=tablist] { overflow-x: auto !important; flex-wrap: nowrap !important; }
54
+ """''',
55
+ "css-tablist")
56
+
57
+ out = src.encode()
58
+ print("NEW sha=%s bytes=%d" % (hashlib.sha256(out).hexdigest(), len(out)), flush=True)
59
+ HfApi(token=os.environ["HF_TOKEN"]).upload_file(path_or_fileobj=out, path_in_repo="app.py", repo_id=REPO, repo_type="space", commit_message="UI fix: reachable tabs on mobile, explicit preset buttons")
60
+ print("UI_PATCH_UPLOADED", flush=True)