19arjun89 commited on
Commit
91db5a0
·
verified ·
1 Parent(s): 79f1e8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -12,7 +12,7 @@ from datasets import load_dataset
12
  # === Config ===
13
  VISITS_URL = os.getenv(
14
  "VISITS_URL",
15
- "https://huggingface.co/datasets/19arjun89/ai_recruiting_agent_usage/resolve/main/usage/visits.jsonl",
16
  )
17
 
18
  # Optional: You can keep this env var, but this version uses Plotly Geo (no Mapbox needed)
@@ -32,11 +32,15 @@ def normalize_country_name(country: str | None) -> str | None:
32
  return c
33
 
34
 
35
- def country_name_to_iso3(country_name: str) -> str | None:
36
- """Convert country name -> ISO3 for mapping."""
 
 
 
 
37
  try:
38
- rec = pycountry.countries.search_fuzzy(country_name)[0]
39
- return rec.alpha_3
40
  except Exception:
41
  return None
42
 
@@ -74,14 +78,16 @@ def build_report():
74
 
75
  for row in load_rows_streaming():
76
  scanned += 1
77
-
78
- country = normalize_country_name(row.get("country"))
 
 
79
  if not country:
80
  continue
81
 
82
  country_counts[country] += 1
83
 
84
- iso3 = country_name_to_iso3(country)
85
  if not iso3:
86
  continue
87
 
 
12
  # === Config ===
13
  VISITS_URL = os.getenv(
14
  "VISITS_URL",
15
+ "https://huggingface.co/datasets/19arjun89/ai_recruiting_agent_usage/resolve/main/usage/visits_enriched.jsonl",
16
  )
17
 
18
  # Optional: You can keep this env var, but this version uses Plotly Geo (no Mapbox needed)
 
32
  return c
33
 
34
 
35
+ def iso2_to_iso3(country_code: str | None) -> str | None:
36
+ if not country_code or not isinstance(country_code, str):
37
+ return None
38
+ c2 = country_code.strip().upper()
39
+ if len(c2) != 2:
40
+ return None
41
  try:
42
+ rec = pycountry.countries.get(alpha_2=c2)
43
+ return rec.alpha_3 if rec else None
44
  except Exception:
45
  return None
46
 
 
78
 
79
  for row in load_rows_streaming():
80
  scanned += 1
81
+ event_type = str(row.get("event", "") or "").strip().lower()
82
+ if event_type == "session_start":
83
+ continue
84
+ country = normalize_country_name(row.get("final_country"))
85
  if not country:
86
  continue
87
 
88
  country_counts[country] += 1
89
 
90
+ iso3 = iso2_to_iso3(row.get("final_country_code"))
91
  if not iso3:
92
  continue
93