Datasets:
Bappadala Rohith Kumar Naidu commited on
Commit Β·
d8b26e4
1
Parent(s): 6a0c11d
fix: move notebooks from root into notebooks/ folder, add READMEs and requirements
Browse files- Moved 5 .ipynb files from root β notebooks/
- notebooks/README.md: Hub-specific guide with notebook index, run order, and output persistence
- scripts/README.md: Pipeline guide with Pro vs basic fetcher comparison
- requirements.txt: Full dependency list for scripts and notebooks
- notebooks/README.md +77 -60
- requirements.txt +25 -0
- scripts/README.md +93 -0
notebooks/README.md
CHANGED
|
@@ -1,69 +1,86 @@
|
|
| 1 |
-
# SafeVisionAI
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
---
|
| 8 |
|
| 9 |
-
##
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
```bash
|
| 21 |
-
!unzip /content/data/chatbot_service/data/pothole_training/road_damage_2025/archive.zip -d /content/data/chatbot_service/data/pothole_training/road_damage_2025/
|
| 22 |
-
```
|
| 23 |
-
|
| 24 |
-
## π Dataset Path Architecture
|
| 25 |
-
|
| 26 |
-
If cloned and linked correctly, the notebooks will automatically find data in:
|
| 27 |
-
|
| 28 |
-
| Feature | Colab Path | Status |
|
| 29 |
-
| :--- | :--- | :--- |
|
| 30 |
-
| **Accidents Data** | `/content/data/chatbot_service/data/accidents/` | Ready |
|
| 31 |
-
| **Legal/Medical PDFs** | `/content/data/chatbot_service/data/legal/*.pdf` | Ready |
|
| 32 |
-
| **Pothole Training** | `/content/data/chatbot_service/data/pothole_training/road_damage_2025/` | **Needs Extract** |
|
| 33 |
-
| **Roads & Tolls** | `/content/data/backend/data/roads/` | Ready |
|
| 34 |
-
| **AI Models (ONNX)** | `/content/data/frontend/public/models/` | Ready |
|
| 35 |
|
| 36 |
---
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
* **Purpose**: Trains a custom YOLOv8 Nano object detection model on the Indian Road Pothole dataset to identify multiple classes: `pothole`, `crack`, and `manhole`. Employs data augmentation and runs for 50 epochs to maximize mAP.
|
| 41 |
-
* **Why we use it**: It acts as the core computer vision engine to warn drivers of upcoming road deformities.
|
| 42 |
-
* **Where the outputs live**:
|
| 43 |
-
* β `frontend/public/models/pothole.onnx` (12MB ONNX artifact used by the browser/app to perform real-time tracking entirely offline).
|
| 44 |
-
* β `backend/models/pothole.pt` (PyTorch artifact utilized by the backend server for heavier image verification/reporting).
|
| 45 |
-
|
| 46 |
-
## π Notebook 2: ChromaDB RAG Vectorstore Build
|
| 47 |
-
* **Purpose**: Ingests thousands of pages of Indian legal Pdfs, MVA (Motor Vehicles Act) penalty charts, and traffic regulations. It utilizes `langchain` and SentenceTransformers to chunk, embed, and store this data in a persistent local SQLite vector store.
|
| 48 |
-
* **Why we use it**: It gives the AI Chatbot absolute knowledge over Indian road laws, ensuring it never hallucinates legal advice.
|
| 49 |
-
* **Where the outputs live**:
|
| 50 |
-
* β `chatbot_service/data/chroma_db/` (The actual `chroma.sqlite3` vectors used by the LangChain retrieval chain).
|
| 51 |
-
|
| 52 |
-
## π Notebook 3: Accident EDA & Hotspot Generator
|
| 53 |
-
* **Purpose**: Analyzes the multi-million row India Accidents GPS dataset. It calculates national statistics, aggregates state-wise fatality rates, and clusters raw GPS tags into definitive geographic "blackspots" (areas with historical fatality density).
|
| 54 |
-
* **Why we use it**: Displays compelling statistics to the user and warns them if their current route is historically dangerous.
|
| 55 |
-
* **Where the outputs live**:
|
| 56 |
-
* β `chatbot_service/data/accidents/blackspot_seed.csv` (Parsed by the SOS and routing engine).
|
| 57 |
-
* β `chatbot_service/data/accidents/accidents_summary.json` & `frontend/public/offline-data/accidents_summary.json` (Used by the UI panels and chatbot context).
|
| 58 |
-
|
| 59 |
-
## π Notebook 4: Roads Data Processing
|
| 60 |
-
* **Purpose**: Cleans and strips down massive tabular highway/toll data. Maps unformatted legacy headers (`name, lat, lon, id`) into clean schemas (`Plaza Name, NH Number`) to reduce the file payload size for mobile clients.
|
| 61 |
-
* **Why we use it**: Prevents the frontend from downloading megabytes of unused CSV columns just to render map markers.
|
| 62 |
-
* **Where the outputs live**:
|
| 63 |
-
* β `backend/data/toll_plazas.json` (Served directly to the Mapbox/Leaflet UI components).
|
| 64 |
-
|
| 65 |
-
## π Notebook 5: Risk Model ONNX Training
|
| 66 |
-
* **Purpose**: Synthesizes environmental data (e.g., weather condition, speed limits, time of day, road type) to train a lightweight `GradientBoostingClassifier` evaluating the current risk probability (Safe vs. Danger) of a drive.
|
| 67 |
-
* **Why we use it**: Generates an ultra-lightweight (15KB) classification model capable of running edge inferences on the user's phone, even in poor-connectivity standard Indian rural areas.
|
| 68 |
-
* **Where the outputs live**:
|
| 69 |
-
* β `frontend/public/models/risk_model.onnx` (Triggered via ONNX.js in the browser frontend).
|
|
|
|
| 1 |
+
# SafeVisionAI β Research Notebooks π
|
| 2 |
|
| 3 |
+
These notebooks are the **research and training layer** of SafeVisionAI. Each one processes raw data from the Hub and produces a model, index, or processed dataset used by the live application.
|
| 4 |
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## β‘ One-Click Colab Setup
|
| 8 |
+
|
| 9 |
+
Run this at the top of **any** notebook to mount the full dataset:
|
| 10 |
+
|
| 11 |
+
```python
|
| 12 |
+
# Step 1 β Clone the Hub (only run once per session)
|
| 13 |
+
!git clone https://huggingface.co/datasets/rohith083/SafeVisionAI-Dataset-Hub /content/hub
|
| 14 |
+
|
| 15 |
+
# Step 2 β Install dependencies
|
| 16 |
+
!pip install -q pdfplumber chromadb sentence-transformers ultralytics onnx
|
| 17 |
+
|
| 18 |
+
# Step 3 β Confirm data is accessible
|
| 19 |
+
import os
|
| 20 |
+
print("Data folders:", os.listdir("/content/hub"))
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## π Notebook Index
|
| 26 |
+
|
| 27 |
+
| # | Notebook | What it Produces | Input Data |
|
| 28 |
+
|---|---|---|---|
|
| 29 |
+
| 1 | `YOLOv8_Pothole_Detector_Training` | ONNX road damage model | `pothole_training/road_damage_2025/` |
|
| 30 |
+
| 2 | `ChromaDB_RAG_Vectorstore_Build` | ChromaDB index for legal RAG | `legal/`, `medical/` PDFs |
|
| 31 |
+
| 3 | `Accident_EDA_&_Hotspot_Generator` | Blackspot seed CSV + heatmap | `accidents/kaggle_india_accidents.csv` |
|
| 32 |
+
| 4 | `Roads_Data_Processing` | Sampled PMGSY GeoJSON | `roads/pmgsy_roads.geojson` |
|
| 33 |
+
| 5 | `Risk_Model_ONNX_Training` | Risk scoring ONNX model | `accidents/` + `roads/` |
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## π Data Paths Used by These Notebooks
|
| 38 |
+
|
| 39 |
+
All notebooks expect data at these paths after cloning the Hub:
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
/content/hub/
|
| 43 |
+
βββ chatbot_service/data/
|
| 44 |
+
β βββ accidents/ β Notebooks 3, 5
|
| 45 |
+
β βββ legal/ β Notebook 2
|
| 46 |
+
β βββ medical/ β Notebook 2
|
| 47 |
+
β βββ pothole_training/ β Notebook 1
|
| 48 |
+
β βββ roads/ β Notebook 4
|
| 49 |
+
βββ backend/datasets/ β Notebook 4, 5
|
| 50 |
+
βββ frontend/public/models/ β Output for Notebooks 1, 5
|
| 51 |
+
```
|
| 52 |
|
| 53 |
---
|
| 54 |
|
| 55 |
+
## π Running Order
|
| 56 |
+
|
| 57 |
+
For a full pipeline run, execute notebooks in this order:
|
| 58 |
+
|
| 59 |
+
```
|
| 60 |
+
1 β Train pothole detector β produces ONNX model
|
| 61 |
+
2 β Build RAG vectorstore β produces ChromaDB index
|
| 62 |
+
3 β Accident EDA β produces blackspot_seed.csv
|
| 63 |
+
4 β Roads processing β produces sampled GeoJSON
|
| 64 |
+
5 β Risk model β combines accidents + roads β risk ONNX
|
| 65 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
---
|
| 68 |
|
| 69 |
+
## πΎ Saving Outputs Back
|
| 70 |
+
|
| 71 |
+
After training, outputs land in `/content/hub/`. To persist them:
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
# Commit outputs back to Hub (requires HF token)
|
| 75 |
+
import os
|
| 76 |
+
os.environ["HUGGING_FACE_TOKEN"] = "your_token_here"
|
| 77 |
+
|
| 78 |
+
!cd /content/hub && git config user.email "you@example.com"
|
| 79 |
+
!cd /content/hub && git config user.name "SafeVisionAI"
|
| 80 |
+
!cd /content/hub && git add . && git commit -m "chore: update trained model outputs"
|
| 81 |
+
!cd /content/hub && git push https://your_username:$HUGGING_FACE_TOKEN@huggingface.co/datasets/rohith083/SafeVisionAI-Dataset-Hub main
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
---
|
| 85 |
|
| 86 |
+
*Part of the [SafeVisionAI](https://github.com/SafeVision-AI/SafeVision-AI) β IIT Madras Road Safety Hackathon 2026*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SafeVisionAI Dataset Hub β Script Dependencies
|
| 2 |
+
# Install with: pip install -r requirements.txt
|
| 3 |
+
|
| 4 |
+
# ββ Core (all scripts) ββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
+
requests>=2.31.0 # HTTP fetching for legal PDF downloader
|
| 6 |
+
|
| 7 |
+
# ββ GIS / Overpass fetchers βββββββββββββββββββββββββββββββββββ
|
| 8 |
+
# No extra deps β fetch_*.py uses only stdlib (urllib, csv, json)
|
| 9 |
+
|
| 10 |
+
# ββ PDF Processing ββββββββββββββββββββββββββββββββββββββββββββ
|
| 11 |
+
pdfplumber>=0.10.0 # extract_morth2022_tables.py
|
| 12 |
+
|
| 13 |
+
# ββ Kaggle Dataset Download βββββββββββββββββββββββββββββββββββ
|
| 14 |
+
kaggle>=1.6.0 # setup_kaggle.ps1 + accident CSV download
|
| 15 |
+
|
| 16 |
+
# ββ Notebook dependencies βββββββββββββββββββββββββββββββββββββ
|
| 17 |
+
ultralytics>=8.0.0 # YOLOv8 pothole detector training
|
| 18 |
+
onnx>=1.15.0 # ONNX model export
|
| 19 |
+
chromadb>=0.4.0 # RAG vectorstore build
|
| 20 |
+
sentence-transformers>=2.2.0 # ChromaDB embeddings
|
| 21 |
+
scikit-learn>=1.3.0 # Risk model training
|
| 22 |
+
pandas>=2.0.0 # Data processing
|
| 23 |
+
geopandas>=0.14.0 # Roads GeoJSON processing
|
| 24 |
+
matplotlib>=3.7.0 # Accident EDA visualizations
|
| 25 |
+
seaborn>=0.12.0 # Heatmap generation
|
scripts/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SafeVisionAI β Data Acquisition Scripts π¬
|
| 2 |
+
|
| 3 |
+
These scripts are the **raw data pipeline** that built the 3.6GB SafeVisionAI dataset.
|
| 4 |
+
All scripts here are **pure Python** β they require no database, no Redis, no PostGIS.
|
| 5 |
+
|
| 6 |
+
> Scripts are mirrored from the [SafeVisionAI main repo](https://github.com/SafeVision-AI/SafeVision-AI) and organized by their origin folder.
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## π Structure
|
| 11 |
+
|
| 12 |
+
```
|
| 13 |
+
scripts/
|
| 14 |
+
βββ scripts/data/ β from SafeVisionAI/scripts/data/
|
| 15 |
+
β βββ fetch_*.py β Overpass GIS fetchers (basic version)
|
| 16 |
+
β βββ _overpass_utils.py β Core GIS utility
|
| 17 |
+
β βββ download_legal_pdfs.py
|
| 18 |
+
β βββ extract_morth2022_tables.py
|
| 19 |
+
β βββ seed_blackspots.py
|
| 20 |
+
β βββ bootstrap_local_data.py
|
| 21 |
+
β βββ verify_data.py
|
| 22 |
+
β βββ inspect_zips.py
|
| 23 |
+
β βββ audit_env.py
|
| 24 |
+
β βββ check_all_scripts.py
|
| 25 |
+
β βββ setup_kaggle.ps1
|
| 26 |
+
β
|
| 27 |
+
βββ backend/data/ β from SafeVisionAI/backend/scripts/data/
|
| 28 |
+
β βββ seed_violations.py β MVA 2019 traffic fine normalizer
|
| 29 |
+
β βββ prepare_road_sources.py
|
| 30 |
+
β βββ sample_pmgsy.py
|
| 31 |
+
β βββ road_sources.example.json
|
| 32 |
+
β
|
| 33 |
+
βββ chatbot_service/data/ β from SafeVisionAI/chatbot_service/scripts/data/
|
| 34 |
+
βββ _overpass_utils.py β β Pro version (retries + backoff)
|
| 35 |
+
βββ fetch_*.py β β Pro fetchers (use these over scripts/data/)
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## π Recommended Run Order
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
# Install dependencies first
|
| 44 |
+
pip install requests pdfplumber
|
| 45 |
+
|
| 46 |
+
# 1. Setup Kaggle API (one-time)
|
| 47 |
+
pwsh scripts/scripts/data/setup_kaggle.ps1
|
| 48 |
+
|
| 49 |
+
# 2. Fetch all emergency services (use Pro versions)
|
| 50 |
+
python scripts/chatbot_service/data/fetch_hospitals.py
|
| 51 |
+
python scripts/chatbot_service/data/fetch_police.py
|
| 52 |
+
python scripts/chatbot_service/data/fetch_ambulance.py
|
| 53 |
+
python scripts/chatbot_service/data/fetch_blood_banks.py
|
| 54 |
+
python scripts/chatbot_service/data/fetch_fire.py
|
| 55 |
+
|
| 56 |
+
# 3. Download legal documents
|
| 57 |
+
python scripts/scripts/data/download_legal_pdfs.py
|
| 58 |
+
|
| 59 |
+
# 4. Extract MoRTH accident tables from PDFs
|
| 60 |
+
python scripts/scripts/data/extract_morth2022_tables.py
|
| 61 |
+
|
| 62 |
+
# 5. Normalize accident blackspot data
|
| 63 |
+
python scripts/scripts/data/seed_blackspots.py
|
| 64 |
+
|
| 65 |
+
# 6. Normalize traffic violations (MVA 2019)
|
| 66 |
+
python scripts/backend/data/seed_violations.py
|
| 67 |
+
|
| 68 |
+
# 7. Verify everything is correct
|
| 69 |
+
python scripts/scripts/data/verify_data.py
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## β Pro vs Basic Fetchers
|
| 75 |
+
|
| 76 |
+
| Feature | `scripts/scripts/data/fetch_*.py` | `scripts/chatbot_service/data/fetch_*.py` |
|
| 77 |
+
|---|---|---|
|
| 78 |
+
| Retry logic | β | β
|
|
| 79 |
+
| Exponential backoff | β | β
|
|
| 80 |
+
| Indian GIS precision | Basic | Enhanced |
|
| 81 |
+
| Extra fields (email, postcode) | β | β
|
|
| 82 |
+
|
| 83 |
+
**Always prefer `chatbot_service/data/` versions** for data acquisition.
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## π¦ Dependencies
|
| 88 |
+
|
| 89 |
+
```
|
| 90 |
+
pip install -r requirements.txt
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
See `requirements.txt` in the Hub root.
|