Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,9 +55,9 @@ def load_rows_streaming():
|
|
| 55 |
|
| 56 |
def build_report(url_contains: str):
|
| 57 |
"""
|
| 58 |
-
Aggregate
|
| 59 |
- Mapbox choropleth (ISO3 internally, country name on hover)
|
| 60 |
-
- Table with country name +
|
| 61 |
"""
|
| 62 |
url_contains = (url_contains or "").strip().lower()
|
| 63 |
|
|
@@ -98,8 +98,8 @@ def build_report(url_contains: str):
|
|
| 98 |
|
| 99 |
# Table dataframe
|
| 100 |
table_df = (
|
| 101 |
-
pd.DataFrame([{"country": k, "
|
| 102 |
-
.sort_values("
|
| 103 |
.reset_index(drop=True)
|
| 104 |
)
|
| 105 |
|
|
@@ -107,11 +107,11 @@ def build_report(url_contains: str):
|
|
| 107 |
map_df = (
|
| 108 |
pd.DataFrame(
|
| 109 |
[
|
| 110 |
-
{"iso3": iso3, "country": iso3_to_name.get(iso3, iso3), "
|
| 111 |
-
for iso3,
|
| 112 |
]
|
| 113 |
)
|
| 114 |
-
.sort_values("
|
| 115 |
.reset_index(drop=True)
|
| 116 |
)
|
| 117 |
|
|
@@ -121,7 +121,7 @@ def build_report(url_contains: str):
|
|
| 121 |
fig.update_layout(height=720, margin=dict(l=0, r=0, t=40, b=0))
|
| 122 |
summary = (
|
| 123 |
f"Rows scanned: {scanned:,} • Rows after URL filter: {matched_url:,} • "
|
| 124 |
-
f"Countries (table): {len(table_df):,} • Total
|
| 125 |
)
|
| 126 |
return fig, table_df.head(50), summary
|
| 127 |
|
|
@@ -129,9 +129,9 @@ def build_report(url_contains: str):
|
|
| 129 |
fig = px.choropleth(
|
| 130 |
map_df,
|
| 131 |
locations="iso3",
|
| 132 |
-
color="
|
| 133 |
hover_name="country", # English country name in tooltip
|
| 134 |
-
hover_data={"
|
| 135 |
projection="natural earth",
|
| 136 |
title=None,
|
| 137 |
)
|
|
@@ -155,7 +155,7 @@ def build_report(url_contains: str):
|
|
| 155 |
|
| 156 |
# Add a simple dashboard-style title
|
| 157 |
fig.add_annotation(
|
| 158 |
-
text="
|
| 159 |
x=0.01,
|
| 160 |
y=0.99,
|
| 161 |
xref="paper",
|
|
@@ -170,7 +170,7 @@ def build_report(url_contains: str):
|
|
| 170 |
summary = (
|
| 171 |
f"Rows scanned: {scanned:,} • Rows after URL filter: {matched_url:,} • "
|
| 172 |
f"Rows mappable: {mappable:,} • Countries (table): {len(table_df):,} • "
|
| 173 |
-
f"Countries (map): {len(map_df):,} • Total
|
| 174 |
)
|
| 175 |
|
| 176 |
return fig, table_df.head(50), summary
|
|
@@ -179,7 +179,7 @@ def build_report(url_contains: str):
|
|
| 179 |
with gr.Blocks(title="AI Recruiting Agent — Usage Map") as demo:
|
| 180 |
gr.Markdown(
|
| 181 |
"# AI Recruiting Agent — Usage by Country\n"
|
| 182 |
-
"This Space reads **only** `usage/visits.jsonl` and plots
|
| 183 |
"- Set **MAPBOX_TOKEN** as a Space *Secret* for the best-looking map.\n"
|
| 184 |
"- (Optional) Filter by `space_url` substring if you ever log multiple spaces."
|
| 185 |
)
|
|
|
|
| 55 |
|
| 56 |
def build_report(url_contains: str):
|
| 57 |
"""
|
| 58 |
+
Aggregate usage events by country and render:
|
| 59 |
- Mapbox choropleth (ISO3 internally, country name on hover)
|
| 60 |
+
- Table with country name + usage events
|
| 61 |
"""
|
| 62 |
url_contains = (url_contains or "").strip().lower()
|
| 63 |
|
|
|
|
| 98 |
|
| 99 |
# Table dataframe
|
| 100 |
table_df = (
|
| 101 |
+
pd.DataFrame([{"country": k, "usage_events": v} for k, v in country_counts.items()])
|
| 102 |
+
.sort_values("usage_events", ascending=False)
|
| 103 |
.reset_index(drop=True)
|
| 104 |
)
|
| 105 |
|
|
|
|
| 107 |
map_df = (
|
| 108 |
pd.DataFrame(
|
| 109 |
[
|
| 110 |
+
{"iso3": iso3, "country": iso3_to_name.get(iso3, iso3), "usage_events": usage_events}
|
| 111 |
+
for iso3, usage_events in iso3_counts.items()
|
| 112 |
]
|
| 113 |
)
|
| 114 |
+
.sort_values("usage_events", ascending=False)
|
| 115 |
.reset_index(drop=True)
|
| 116 |
)
|
| 117 |
|
|
|
|
| 121 |
fig.update_layout(height=720, margin=dict(l=0, r=0, t=40, b=0))
|
| 122 |
summary = (
|
| 123 |
f"Rows scanned: {scanned:,} • Rows after URL filter: {matched_url:,} • "
|
| 124 |
+
f"Countries (table): {len(table_df):,} • Total Usage Events: {int(table_df['usage_events'].sum()) if len(table_df) else 0:,}"
|
| 125 |
)
|
| 126 |
return fig, table_df.head(50), summary
|
| 127 |
|
|
|
|
| 129 |
fig = px.choropleth(
|
| 130 |
map_df,
|
| 131 |
locations="iso3",
|
| 132 |
+
color="usage_events",
|
| 133 |
hover_name="country", # English country name in tooltip
|
| 134 |
+
hover_data={"usage_events": True, "iso3": False}, # show usage_events only
|
| 135 |
projection="natural earth",
|
| 136 |
title=None,
|
| 137 |
)
|
|
|
|
| 155 |
|
| 156 |
# Add a simple dashboard-style title
|
| 157 |
fig.add_annotation(
|
| 158 |
+
text="Usage Events by Country",
|
| 159 |
x=0.01,
|
| 160 |
y=0.99,
|
| 161 |
xref="paper",
|
|
|
|
| 170 |
summary = (
|
| 171 |
f"Rows scanned: {scanned:,} • Rows after URL filter: {matched_url:,} • "
|
| 172 |
f"Rows mappable: {mappable:,} • Countries (table): {len(table_df):,} • "
|
| 173 |
+
f"Countries (map): {len(map_df):,} • Total Usage Events: {int(table_df['usage_events'].sum()) if len(table_df) else 0:,}"
|
| 174 |
)
|
| 175 |
|
| 176 |
return fig, table_df.head(50), summary
|
|
|
|
| 179 |
with gr.Blocks(title="AI Recruiting Agent — Usage Map") as demo:
|
| 180 |
gr.Markdown(
|
| 181 |
"# AI Recruiting Agent — Usage by Country\n"
|
| 182 |
+
"This Space reads **only** `usage/visits.jsonl` and plots usage events by country.\n\n"
|
| 183 |
"- Set **MAPBOX_TOKEN** as a Space *Secret* for the best-looking map.\n"
|
| 184 |
"- (Optional) Filter by `space_url` substring if you ever log multiple spaces."
|
| 185 |
)
|