ginnyxxxxxxx commited on
Commit
dc29dcc
Β·
1 Parent(s): 1985a84

agent update

Browse files
Files changed (1) hide show
  1. app.py +53 -22
app.py CHANGED
@@ -526,29 +526,55 @@ def on_select_reset(agent_id):
526
  return map_html, summary, raw_text, demo_text, chain_html, 0, gr.update(value="β–Ά Stage 1: Feature Extraction")
527
 
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  # ── UI ────────────────────────────────────────────────────────────────────────
530
 
531
  with gr.Blocks(title="HiCoTraj Demo", theme=gr.themes.Soft()) as app:
532
  gr.Markdown("## HiCoTraj β€” Trajectory Visualization & Hierarchical CoT Demo")
533
  gr.Markdown("*Zero-Shot Demographic Reasoning via Hierarchical Chain-of-Thought Prompting from Trajectory* Β· ACM SIGSPATIAL GeoGenAgent 2025")
534
  gr.Markdown("""
535
- **Dataset:** NUMOSIM[1]
536
  > [1]Stanford C, Adari S, Liao X, et al. *NUMoSim: A Synthetic Mobility Dataset with Anomaly Detection Benchmarks.* ACM SIGSPATIAL Workshop on Geospatial Anomaly Detection, 2024.
537
-
538
  """)
539
 
540
- with gr.Row():
541
- agent_dd = gr.Dropdown(
542
- choices=[str(a) for a in sample_agents],
543
- label="Select Agent",
544
- value=str(sample_agents[0]),
545
- scale=1
546
- )
547
- demo_label = gr.Textbox(
548
- label="Ground Truth Demographics",
549
- interactive=False,
550
- scale=4
551
- )
552
 
553
  with gr.Row():
554
  with gr.Column(scale=1):
@@ -568,16 +594,21 @@ with gr.Blocks(title="HiCoTraj Demo", theme=gr.themes.Soft()) as app:
568
  run_btn = gr.Button("β–Ά Stage 1: Feature Extraction", variant="primary")
569
  chain_out = gr.HTML(value=render_chain("", "", "", status="idle"))
570
 
571
- agent_dd.change(
572
- fn=on_select_reset, inputs=agent_dd,
573
- outputs=[map_out, summary_out, raw_out, demo_label, chain_out, step_state, run_btn]
 
 
 
 
 
574
  )
575
  app.load(
576
- fn=on_select_reset, inputs=agent_dd,
577
- outputs=[map_out, summary_out, raw_out, demo_label, chain_out, step_state, run_btn]
578
  )
579
  run_btn.click(
580
- fn=handle_btn, inputs=[agent_dd, step_state],
581
  outputs=[chain_out, step_state, run_btn]
582
  )
583
 
@@ -590,8 +621,8 @@ with gr.Blocks(title="HiCoTraj Demo", theme=gr.themes.Soft()) as app:
590
  return build_weekly_checkin(agent_sp, max_days=2), gr.update(value="Show All Days")
591
 
592
  show_all_btn.click(
593
- fn=toggle_raw, inputs=[agent_dd, raw_out],
594
  outputs=[raw_out, show_all_btn]
595
  )
596
 
597
- app.launch(show_error=True, share=True)
 
526
  return map_html, summary, raw_text, demo_text, chain_html, 0, gr.update(value="β–Ά Stage 1: Feature Extraction")
527
 
528
 
529
+
530
+ SHOWCASE_AGENTS = sample_agents[:8]
531
+
532
+
533
+ def build_agent_cards(selected_id):
534
+ selected_id = int(selected_id)
535
+ parts = []
536
+ parts.append("<div style='display:grid;grid-template-columns:repeat(4,1fr);gap:10px;padding:4px 0;'>")
537
+ for aid in SHOWCASE_AGENTS:
538
+ row = demo[demo["agent_id"] == aid].iloc[0]
539
+ age = int(row["age"]) if row["age"] > 0 else "?"
540
+ sex = SEX_MAP.get(int(row["sex"]), "?")
541
+ edu = EDU_MAP.get(int(row["education"]), "?")
542
+ inc = INC_MAP.get(int(row["hh_income"]), "?")
543
+ is_sel = (aid == selected_id)
544
+ sel_style = "border:2px solid #c0392b;background:#fff8f8;box-shadow:0 2px 8px rgba(192,57,43,0.15);"
545
+ nor_style = "border:1.5px solid #ddd;background:#fafafa;box-shadow:0 1px 3px rgba(0,0,0,0.06);"
546
+ style = sel_style if is_sel else nor_style
547
+ dot = "<span style='display:inline-block;width:8px;height:8px;border-radius:50%;background:#c0392b;margin-right:5px;'></span>" if is_sel else ""
548
+ js = "var t=document.querySelector('#agent_hidden_input textarea');t.value='AID';t.dispatchEvent(new Event('input',{bubbles:true}));".replace("AID", str(aid))
549
+ parts.append(
550
+ "<div onclick=\"" + js + "\" style=\"cursor:pointer;border-radius:10px;padding:10px 13px;transition:all 0.2s;" + style + "\">"
551
+ "<div style='font-size:11px;font-weight:700;color:#c0392b;margin-bottom:3px;font-family:monospace;'>" + dot + "Agent #" + str(aid) + "</div>"
552
+ "<div style='font-size:11px;color:#333;line-height:1.6;'>"
553
+ "<b>Age:</b> " + str(age) + " &nbsp; <b>Sex:</b> " + sex + "<br>"
554
+ "<b>Edu:</b> " + edu + "<br>"
555
+ "<b>Income:</b> " + inc + "</div></div>"
556
+ )
557
+ parts.append("</div>")
558
+ return "".join(parts)
559
+
560
+
561
  # ── UI ────────────────────────────────────────────────────────────────────────
562
 
563
  with gr.Blocks(title="HiCoTraj Demo", theme=gr.themes.Soft()) as app:
564
  gr.Markdown("## HiCoTraj β€” Trajectory Visualization & Hierarchical CoT Demo")
565
  gr.Markdown("*Zero-Shot Demographic Reasoning via Hierarchical Chain-of-Thought Prompting from Trajectory* Β· ACM SIGSPATIAL GeoGenAgent 2025")
566
  gr.Markdown("""
567
+ **Dataset:** NUMOSIM [1]
568
  > [1]Stanford C, Adari S, Liao X, et al. *NUMoSim: A Synthetic Mobility Dataset with Anomaly Detection Benchmarks.* ACM SIGSPATIAL Workshop on Geospatial Anomaly Detection, 2024.
 
569
  """)
570
 
571
+ gr.Markdown("### Select Agent")
572
+ agent_cards = gr.HTML(value=build_agent_cards(SHOWCASE_AGENTS[0]))
573
+ agent_hidden = gr.Textbox(
574
+ value=str(SHOWCASE_AGENTS[0]),
575
+ visible=False,
576
+ elem_id="agent_hidden_input"
577
+ )
 
 
 
 
 
578
 
579
  with gr.Row():
580
  with gr.Column(scale=1):
 
594
  run_btn = gr.Button("β–Ά Stage 1: Feature Extraction", variant="primary")
595
  chain_out = gr.HTML(value=render_chain("", "", "", status="idle"))
596
 
597
+ def on_agent_click(agent_id):
598
+ cards_html = build_agent_cards(agent_id)
599
+ map_html, summary, raw_text, chain_html, step, btn = on_select_reset(agent_id)
600
+ return cards_html, map_html, summary, raw_text, chain_html, step, btn
601
+
602
+ agent_hidden.change(
603
+ fn=on_agent_click, inputs=agent_hidden,
604
+ outputs=[agent_cards, map_out, summary_out, raw_out, chain_out, step_state, run_btn]
605
  )
606
  app.load(
607
+ fn=on_select_reset, inputs=agent_hidden,
608
+ outputs=[map_out, summary_out, raw_out, chain_out, step_state, run_btn]
609
  )
610
  run_btn.click(
611
+ fn=handle_btn, inputs=[agent_hidden, step_state],
612
  outputs=[chain_out, step_state, run_btn]
613
  )
614
 
 
621
  return build_weekly_checkin(agent_sp, max_days=2), gr.update(value="Show All Days")
622
 
623
  show_all_btn.click(
624
+ fn=toggle_raw, inputs=[agent_hidden, raw_out],
625
  outputs=[raw_out, show_all_btn]
626
  )
627
 
628
+ app.launch(show_error=True)