Spaces:
Running
Running
Commit Β·
6bf5fce
1
Parent(s): 510cf41
outline
Browse files
app.py
CHANGED
|
@@ -733,12 +733,12 @@ def render_chain(s1_text, s2_text, s3_text, status="idle",
|
|
| 733 |
'<div class="hct-flow-steps">'
|
| 734 |
'<div class="hct-flow-step">'
|
| 735 |
'<div class="hct-flow-step-label">Raw Data</div>'
|
| 736 |
-
'<div class="hct-flow-step-desc">Stay points + POI metadata<br><span style="color:#8090b0;font-size:10px">
|
| 737 |
'</div>'
|
| 738 |
'<div class="hct-flow-arrow">β</div>'
|
| 739 |
'<div class="hct-flow-step">'
|
| 740 |
-
'<div class="hct-flow-step-label">
|
| 741 |
-
'<div class="hct-flow-step-desc">Detailed
|
| 742 |
'</div>'
|
| 743 |
'<div class="hct-flow-arrow">β</div>'
|
| 744 |
'<div class="hct-flow-step" style="border-color:#b0bce8;background:#f4f6fb;">'
|
|
@@ -833,6 +833,27 @@ def build_demo_text(row):
|
|
| 833 |
)
|
| 834 |
|
| 835 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
# ββ Callbacks βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 837 |
|
| 838 |
def on_select(agent_id):
|
|
@@ -884,7 +905,8 @@ def on_select_reset(agent_id):
|
|
| 884 |
extra = len(parts) - 1
|
| 885 |
raw_text = parts[0] + (sep.join([""] + parts[1:2]) + ("\n\n... ({} more days)".format(extra - 1) if extra > 1 else "")) if extra > 0 else raw_full
|
| 886 |
chain_html = render_chain("", "", "", status="idle")
|
| 887 |
-
|
|
|
|
| 888 |
|
| 889 |
|
| 890 |
SHOWCASE_AGENTS = sample_agents[:6]
|
|
@@ -942,11 +964,13 @@ with gr.Blocks(title="HiCoTraj Demo") as app:
|
|
| 942 |
with gr.Column(scale=1):
|
| 943 |
gr.Markdown("### Trajectory Map")
|
| 944 |
map_out = gr.HTML()
|
| 945 |
-
gr.Markdown("###
|
| 946 |
with gr.Tabs():
|
| 947 |
-
with gr.Tab("
|
|
|
|
|
|
|
| 948 |
summary_out = gr.Textbox(lines=10, interactive=False, label="", show_label=False)
|
| 949 |
-
with gr.Tab("
|
| 950 |
raw_out = gr.Textbox(lines=10, interactive=False, label="", show_label=False)
|
| 951 |
show_all_btn = gr.Button("Show All Days", size="sm", variant="secondary")
|
| 952 |
|
|
@@ -958,21 +982,21 @@ with gr.Blocks(title="HiCoTraj Demo") as app:
|
|
| 958 |
|
| 959 |
def on_agent_click(agent_id):
|
| 960 |
cards_html = build_agent_cards(agent_id)
|
| 961 |
-
map_html, summary, raw_text, _demo_text, chain_html, step, btn = on_select_reset(agent_id)
|
| 962 |
-
return cards_html, map_html, summary, raw_text, chain_html, step, btn
|
| 963 |
|
| 964 |
agent_hidden.change(
|
| 965 |
fn=on_agent_click, inputs=agent_hidden,
|
| 966 |
-
outputs=[agent_cards, map_out, summary_out, raw_out, chain_out, step_state, run_btn]
|
| 967 |
)
|
| 968 |
|
| 969 |
def on_load(agent_id):
|
| 970 |
-
map_html, summary, raw_text, _demo_text, chain_html, step, btn = on_select_reset(agent_id)
|
| 971 |
-
return map_html, summary, raw_text, chain_html, step, btn
|
| 972 |
|
| 973 |
app.load(
|
| 974 |
fn=on_load, inputs=agent_hidden,
|
| 975 |
-
outputs=[map_out, summary_out, raw_out, chain_out, step_state, run_btn]
|
| 976 |
)
|
| 977 |
run_btn.click(
|
| 978 |
fn=handle_btn, inputs=[agent_hidden, step_state],
|
|
|
|
| 733 |
'<div class="hct-flow-steps">'
|
| 734 |
'<div class="hct-flow-step">'
|
| 735 |
'<div class="hct-flow-step-label">Raw Data</div>'
|
| 736 |
+
'<div class="hct-flow-step-desc">Stay points + POI metadata<br><span style="color:#8090b0;font-size:10px">β Raw Stay Points tab</span></div>'
|
| 737 |
'</div>'
|
| 738 |
'<div class="hct-flow-arrow">β</div>'
|
| 739 |
'<div class="hct-flow-step">'
|
| 740 |
+
'<div class="hct-flow-step-label">Activity Chronicles</div>'
|
| 741 |
+
'<div class="hct-flow-step-desc">Detailed Chronicles + Visiting Summaries<br><span style="color:#8090b0;font-size:10px">β‘ β’ tabs Β· micro + macro level</span></div>'
|
| 742 |
'</div>'
|
| 743 |
'<div class="hct-flow-arrow">β</div>'
|
| 744 |
'<div class="hct-flow-step" style="border-color:#b0bce8;background:#f4f6fb;">'
|
|
|
|
| 833 |
)
|
| 834 |
|
| 835 |
|
| 836 |
+
def build_raw_staypoints(agent_sp, n=12):
|
| 837 |
+
cols = ["start_datetime", "end_datetime", "duration_min", "name", "act_label"]
|
| 838 |
+
df = agent_sp[cols].head(n).copy()
|
| 839 |
+
df["start_datetime"] = df["start_datetime"].dt.strftime("%m/%d %H:%M")
|
| 840 |
+
df["end_datetime"] = df["end_datetime"].dt.strftime("%H:%M")
|
| 841 |
+
df["duration_min"] = df["duration_min"].astype(int).astype(str) + " min"
|
| 842 |
+
df.columns = ["Start", "End", "Duration", "Venue", "Activity"]
|
| 843 |
+
lines = ["Stay Points (raw input β first {} records)".format(n), ""]
|
| 844 |
+
col_w = {"Start": 11, "End": 7, "Duration": 9, "Venue": 28, "Activity": 18}
|
| 845 |
+
header = " ".join(k.ljust(v) for k, v in col_w.items())
|
| 846 |
+
lines.append(header)
|
| 847 |
+
lines.append("-" * len(header))
|
| 848 |
+
for _, row in df.iterrows():
|
| 849 |
+
line = " ".join(str(row[k]).ljust(v)[:v] for k, v in col_w.items())
|
| 850 |
+
lines.append(line)
|
| 851 |
+
lines.append("")
|
| 852 |
+
lines.append("β These records are transformed into Activity Chronicles (Detailed + Visiting Summaries)")
|
| 853 |
+
lines.append(" and fed into Prompt 1 for factual feature extraction.")
|
| 854 |
+
return "\n".join(lines)
|
| 855 |
+
|
| 856 |
+
|
| 857 |
# ββ Callbacks βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 858 |
|
| 859 |
def on_select(agent_id):
|
|
|
|
| 905 |
extra = len(parts) - 1
|
| 906 |
raw_text = parts[0] + (sep.join([""] + parts[1:2]) + ("\n\n... ({} more days)".format(extra - 1) if extra > 1 else "")) if extra > 0 else raw_full
|
| 907 |
chain_html = render_chain("", "", "", status="idle")
|
| 908 |
+
raw_sp_text = build_raw_staypoints(agent_sp)
|
| 909 |
+
return map_html, raw_sp_text, summary, raw_text, demo_text, chain_html, 0, gr.update(value="βΆ Stage 1: Feature Extraction")
|
| 910 |
|
| 911 |
|
| 912 |
SHOWCASE_AGENTS = sample_agents[:6]
|
|
|
|
| 964 |
with gr.Column(scale=1):
|
| 965 |
gr.Markdown("### Trajectory Map")
|
| 966 |
map_out = gr.HTML()
|
| 967 |
+
gr.Markdown("### Mobility Data")
|
| 968 |
with gr.Tabs():
|
| 969 |
+
with gr.Tab("β Raw Stay Points"):
|
| 970 |
+
sp_out = gr.Textbox(lines=10, interactive=False, label="", show_label=False)
|
| 971 |
+
with gr.Tab("β‘ Visiting Summaries"):
|
| 972 |
summary_out = gr.Textbox(lines=10, interactive=False, label="", show_label=False)
|
| 973 |
+
with gr.Tab("β’ Activity Chronicles"):
|
| 974 |
raw_out = gr.Textbox(lines=10, interactive=False, label="", show_label=False)
|
| 975 |
show_all_btn = gr.Button("Show All Days", size="sm", variant="secondary")
|
| 976 |
|
|
|
|
| 982 |
|
| 983 |
def on_agent_click(agent_id):
|
| 984 |
cards_html = build_agent_cards(agent_id)
|
| 985 |
+
map_html, raw_sp, summary, raw_text, _demo_text, chain_html, step, btn = on_select_reset(agent_id)
|
| 986 |
+
return cards_html, map_html, raw_sp, summary, raw_text, chain_html, step, btn
|
| 987 |
|
| 988 |
agent_hidden.change(
|
| 989 |
fn=on_agent_click, inputs=agent_hidden,
|
| 990 |
+
outputs=[agent_cards, map_out, sp_out, summary_out, raw_out, chain_out, step_state, run_btn]
|
| 991 |
)
|
| 992 |
|
| 993 |
def on_load(agent_id):
|
| 994 |
+
map_html, raw_sp, summary, raw_text, _demo_text, chain_html, step, btn = on_select_reset(agent_id)
|
| 995 |
+
return map_html, raw_sp, summary, raw_text, chain_html, step, btn
|
| 996 |
|
| 997 |
app.load(
|
| 998 |
fn=on_load, inputs=agent_hidden,
|
| 999 |
+
outputs=[map_out, sp_out, summary_out, raw_out, chain_out, step_state, run_btn]
|
| 1000 |
)
|
| 1001 |
run_btn.click(
|
| 1002 |
fn=handle_btn, inputs=[agent_hidden, step_state],
|