How jatin-goyal-552/osdhack-22_accidentdetectionai works
Project type and purpose
• This is a full-stack web application with an integrated machine-learning component.
• Purpose: continuously monitor a video feed (highway traffic), run an accident-detection ML model (YOLO, PyTorch), and—upon detecting an accident—automatically notify nearby hospitals via email (including a Google Maps link) so that ambulances can be dispatched.
Main components of the system
a. Video Capture & ML Inference
• accidentdetectionapp/stream.py: captures frames (e.g., from highway_accident.mp4 or live camera)
• PyTorch model files accident2.pt and best (2).pt (YOLO-based accident detector)
• ML inference engine (runs inside Django or as a separate microservice)
b. Django Backend
• AccidentDetection/ (project config: settings.py, urls.py, wsgi.py/asgi.py)
• accidentdetectionapp/ (app code: views.py, urls.py, models.py, admin.py, migrations/)
• test.py (standalone test harness)
c. Database
• SQLite (db.sqlite3) for storing registered hospitals and incoming accident alerts
d. Front-end UI
• Templates: index.html (video display), hospital.html (hospital dashboard), register.html, test.html, etc.
• Static assets: CSS (static/css/style.css), JS (static/javascript/video.js)
• Bootstrap, custom JS for live video and AJAX calls
e. Notification & External Services
• Email (SMTP server configured in settings.py) to send alert + Google Maps link
• Google Maps API (for location links embedded in email)
Relationships and interactions
1. Client browser (ambulance driver or admin) opens index.html → requests video stream endpoint in Django
2. stream.py captures frames → passes them to the PyTorch model → if accident detected → triggers a Django view
3. View: saves an AccidentAlert record (models.py) in SQLite → looks up nearby hospitals (from DB) → sends emails with map links
4. Registered hospital users log in via hospital.html → see incoming alerts → accept or decline
5. On acceptance, another email (or webhook) can be sent to the ambulance driver with precise coordinates
Architectural patterns & design principles
• Layered architecture:
· Presentation layer (templates, static assets)
· Application layer (Django views, URL routing)
· ML inference layer (stream.py + PyTorch)
· Data layer (Django ORM + SQLite)
• Single-process vs. Microservice: ML inference can live inside Django or be split into a separate service behind an API
• Event-driven flow: detection event → alert workflow → email notifications