CoolFace
Datasetpublic

SafeVixAI/SafeVixAI-Dataset-Hub

SafeVixAI Dataset Hub 🛡️ The Intelligence Layer for the SafeVixAI platform — IIT Madras Road Safety Hackathon 2026 This repository hosts all datasets, pre-trained models, notebooks, and reproducible data acquisition scripts that power the SafeVixAI application. It is designed to be cloned directly into Google Colab or any research environment. Main Application Repo: SafeVixAI/SafeVixAI ⚡ Quickstart (Google Colab) # Clone the entire intelligence layer !git… See the full description on the dataset page: https://huggingface.co/datasets/SafeVixAI/SafeVixAI-Dataset-Hub.

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
1likes145downloads
seed_emergency_data.py211 linesDownload Raw Back to data
1#!/usr/bin/env python32"""3Seed Script: India Emergency Data via Overpass API4Generates blood banks, police stations, and fire stations for 25 cities.5Run: python scripts/seed_emergency_data.py6 7Output:8  datasets/emergency/blood_banks/india_blood_banks.json9  datasets/emergency/hospitals/india_hospitals_top25.json10  datasets/police/stations/india_police_stations.json11"""12import asyncio13import json14import sys15import time16from pathlib import Path17 18try:19    import httpx20except ImportError:21    print("Install httpx: pip install httpx")22    sys.exit(1)23 24OVERPASS_URLS = [25    "https://overpass-api.de/api/interpreter",26    "https://overpass.kumi.systems/api/interpreter",27]28 29# Top 25 India cities with bounding boxes [south, west, north, east]30CITIES = {31    "chennai":          [12.8, 80.1, 13.3, 80.4],32    "mumbai":           [18.8, 72.7, 19.3, 73.0],33    "delhi":            [28.4, 76.9, 28.9, 77.4],34    "bengaluru":        [12.8, 77.4, 13.2, 77.8],35    "hyderabad":        [17.2, 78.3, 17.6, 78.6],36    "kolkata":          [22.4, 88.2, 22.7, 88.5],37    "pune":             [18.4, 73.7, 18.6, 74.0],38    "ahmedabad":        [22.9, 72.4, 23.2, 72.7],39    "jaipur":           [26.8, 75.7, 27.0, 75.9],40    "lucknow":          [26.7, 80.8, 27.0, 81.1],41    "surat":            [21.1, 72.7, 21.3, 73.0],42    "nagpur":           [21.0, 78.9, 21.3, 79.2],43    "patna":            [25.5, 85.0, 25.7, 85.2],44    "indore":           [22.6, 75.7, 22.8, 75.9],45    "bhopal":           [23.1, 77.3, 23.3, 77.5],46    "coimbatore":       [10.9, 76.8, 11.1, 77.1],47    "visakhapatnam":    [17.6, 83.1, 17.8, 83.3],48    "kochi":            [9.9, 76.2, 10.1, 76.4],49    "vadodara":         [22.2, 73.1, 22.4, 73.3],50    "amritsar":         [31.6, 74.8, 31.7, 74.9],51    "ranchi":           [23.2, 85.2, 23.5, 85.4],52    "chandigarh":       [30.6, 76.7, 30.8, 76.9],53    "guwahati":         [26.1, 91.6, 26.2, 91.9],54    "bhubaneswar":      [20.2, 85.7, 20.4, 85.9],55    "thiruvananthapuram": [8.4, 76.8, 8.6, 77.0],56}57 58 59async def query_overpass(query: str, retries: int = 3) -> dict:60    """Execute Overpass query with retry across multiple endpoints."""61    headers = {62        "User-Agent": "SafeVixAI/2.0 Emergency Data Seeder (contact@safevixai.in)",63        "Accept": "application/json",64    }65    async with httpx.AsyncClient(timeout=60, headers=headers) as client:66        for attempt in range(retries):67            for url in OVERPASS_URLS:68                try:69                    resp = await client.post(url, data={"data": query})70                    resp.raise_for_status()71                    return resp.json()72                except Exception as e:73                    print(f"  [WARN] {url} failed: {e}")74                    await asyncio.sleep(2)75    return {"elements": []}76 77 78def build_query(bbox: list, amenity_filter: str) -> str:79    s, w, n, e = bbox80    return f"""81[out:json][timeout:30];82(83  node[{amenity_filter}]({s},{w},{n},{e});84  way[{amenity_filter}]({s},{w},{n},{e});85);86out center tags;87""".strip()88 89 90def extract_elements(data: dict, city: str, category: str) -> list:91    items = []92    for el in data.get("elements", []):93        tags = el.get("tags", {})94        lat = el.get("lat") or el.get("center", {}).get("lat")95        lon = el.get("lon") or el.get("center", {}).get("lon")96        if lat is None or lon is None:97            continue98        items.append({99            "id": f"{city}-{el['id']}",100            "name": tags.get("name") or f"{category.title()} ({city})",101            "category": category,102            "city": city,103            "lat": float(lat),104            "lon": float(lon),105            "phone": tags.get("phone") or tags.get("contact:phone"),106            "address": ", ".join(filter(None, [107                tags.get("addr:housenumber"),108                tags.get("addr:street"),109                tags.get("addr:suburb"),110                tags.get("addr:city") or city.title(),111            ])) or None,112            "is_24hr": tags.get("opening_hours") == "24/7",113            "source": "overpass",114        })115    return items116 117 118async def seed_blood_banks():119    """Seed India blood banks from Overpass OSM data."""120    print("\n[BLOOD BANKS] Seeding blood banks...")121    all_items = []122    for city, bbox in CITIES.items():123        query = build_query(bbox, 'amenity="blood_bank"')124        data = await query_overpass(query)125        items = extract_elements(data, city, "blood_bank")126        all_items.extend(items)127        print(f"  {city}: {len(items)} blood banks")128        await asyncio.sleep(1)  # Rate limit129 130    out_path = Path(__file__).parents[2] / "datasets" / "emergency" / "blood_banks" / "india_blood_banks.json"131    out_path.parent.mkdir(parents=True, exist_ok=True)132    with open(out_path, "w") as f:133        json.dump(all_items, f, indent=2)134    print(f"[OK] Saved {len(all_items)} blood banks -> {out_path}")135 136 137async def seed_police_stations():138    """Seed India police stations from Overpass OSM data."""139    print("\n[POLICE] Seeding police stations...")140    all_items = []141    for city, bbox in CITIES.items():142        query = build_query(bbox, 'amenity="police"')143        data = await query_overpass(query)144        items = extract_elements(data, city, "police")145        all_items.extend(items)146        print(f"  {city}: {len(items)} police stations")147        await asyncio.sleep(1)148 149    out_path = Path(__file__).parents[2] / "datasets" / "police" / "stations" / "india_police_stations.json"150    out_path.parent.mkdir(parents=True, exist_ok=True)151    with open(out_path, "w") as f:152        json.dump(all_items, f, indent=2)153    print(f"[OK] Saved {len(all_items)} police stations -> {out_path}")154 155 156async def seed_fire_stations():157    """Seed India fire stations from Overpass OSM data."""158    print("\n[FIRE] Seeding fire stations...")159    all_items = []160    for city, bbox in CITIES.items():161        query = build_query(bbox, 'amenity="fire_station"')162        data = await query_overpass(query)163        items = extract_elements(data, city, "fire")164        all_items.extend(items)165        print(f"  {city}: {len(items)} fire stations")166        await asyncio.sleep(1)167 168    out_path = Path(__file__).parents[2] / "datasets" / "emergency" / "hospitals" / "india_fire_stations.json"169    out_path.parent.mkdir(parents=True, exist_ok=True)170    with open(out_path, "w") as f:171        json.dump(all_items, f, indent=2)172    print(f"[OK] Saved {len(all_items)} fire stations -> {out_path}")173 174 175async def seed_hospitals():176    """Seed top-tier India hospitals with trauma/ICU flags."""177    print("\n[HOSPITALS] Seeding hospitals...")178    all_items = []179    for city, bbox in CITIES.items():180        query = build_query(bbox, 'amenity="hospital"')181        data = await query_overpass(query)182        items = extract_elements(data, city, "hospital")183        # Tag trauma centres and ICU hospitals184        for item in items:185            name_lower = item["name"].lower()186            item["has_trauma"] = "trauma" in name_lower or "aiims" in name_lower187            item["has_icu"] = "icu" in name_lower or "government" in name_lower188        all_items.extend(items)189        print(f"  {city}: {len(items)} hospitals")190        await asyncio.sleep(1)191 192    out_path = Path(__file__).parents[2] / "datasets" / "emergency" / "hospitals" / "india_hospitals_top25.json"193    out_path.parent.mkdir(parents=True, exist_ok=True)194    with open(out_path, "w") as f:195        json.dump(all_items, f, indent=2)196    print(f"[OK] Saved {len(all_items)} hospitals -> {out_path}")197 198 199async def main():200    start = time.time()201    await seed_blood_banks()202    await seed_police_stations()203    await seed_fire_stations()204    await seed_hospitals()205    elapsed = time.time() - start206    print(f"\n[DONE] All seeding done in {elapsed:.1f}s")207 208 209if __name__ == "__main__":210    asyncio.run(main())211