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

Files changed (3) hide show
  1. notebooks/README.md +77 -60
  2. requirements.txt +25 -0
  3. scripts/README.md +93 -0
notebooks/README.md CHANGED
@@ -1,69 +1,86 @@
1
- # SafeVisionAI - Data Science & ML Pipelines
2
 
3
- This directory contains the original Google Colab / Jupyter notebooks utilized to train the machine learning models and process the massive datasets for the SafeVisionAI platform.
4
 
5
- The outputs from these notebooks form the entire "intelligence" layer of the application, driving everything from the real-time webcam inference to the RAG chatbot.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  ---
8
 
9
- ## πŸš€ Getting Started in Colab (Fastest Way)
10
-
11
- 1. **Clone the Data Hub**: Since we moved the data to Hugging Face, you can clone the entire hub directly into your session:
12
- ```bash
13
- # Clone the Hub
14
- !git clone https://huggingface.co/datasets/rohith083/SafeVisionAI-Dataset-Hub /content/dataset_hub
15
-
16
- # Link the data folder so notebooks find it at /content/data
17
- !ln -s /content/dataset_hub/data /content/data
18
- ```
19
- 2. **Extract Dataset Archives**: Some datasets are double-zipped. Run this to extract the pothole training data:
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
- ## πŸ““ Notebook 1: YOLOv8 Pothole Detector Training
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.