Skip to content

Poushali-02/road-accident

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš— Pick the Safer Road Game ๐Ÿ

Road Safety AI Game - Test your intuition about road safety with an AI-powered prediction model!

๐ŸŽฎ Game Overview

Pick the Safer Road is an interactive web game where players compete against time to identify which of two road scenarios is safer. The game uses a trained machine learning model to predict accident rates based on road conditions.

๐ŸŽฏ How to Play

  1. Click "START GAME" - A timer begins
  2. Analyze two road scenarios with different conditions (weather, lighting, road type, etc.)
  3. Choose the safer road before time runs out
  4. Earn points based on speed - Quick answers = more points
  5. Win at 50 points - Complete 10 rounds or reach 50 points first
  6. Track your winning streak - How many games can you win in a row?

๐Ÿ“Š Scoring System

  • Maximum: 10 points per round for correct answers
  • Time-based deduction: -1 point per 10 seconds
  • Minimum: 0 seconds (wrong answers = 0 points)
  • Winning threshold: 50 points across all rounds
  • Instant win: Game stops immediately after reaching 50 points

๐Ÿ† Features

  • โฑ๏ธ Time pressure - Race against the clock to maximize points
  • ๐ŸŽฒ Random scenarios - Ensures significantly different predictions
  • ๐Ÿ“Š Score tracking - Total score, round counter, points needed
  • ๐Ÿ”ฅ Winning streak - Highlighted metric showing consecutive wins
  • ๐ŸŽ‰ Instant win detection - Game ends as soon as 50 points reached
  • ๐Ÿ“ˆ Round-by-round breakdown - See your score history
  • ๐ŸŽจ Beautiful UI - Colorful, responsive design with gradients

๐Ÿš€ Live Server

๐ŸŒ Play Now: https://road-accident-vseuhvwqersrexrv7fxncg.streamlit.app/

The game is live and ready to play! No installation needed - just click and start playing.


๐Ÿ› ๏ธ Setup Instructions

Prerequisites

  • Conda (Anaconda or Miniconda installed)
  • Git (for cloning the repository)
  • Python 3.10 (specified in environment.yml)

Step 1: Clone the Repository

git clone https://github.com/Poushali-02/road-accident.git
cd road-accident

Step 2: Create Conda Environment

Using the provided environment.yml:

conda env create -f environment.yml

This will create a conda environment named accident with all required dependencies at their exact versions.

Step 3: Activate the Environment

conda activate accident

You should see (accident) in your terminal prompt.

Step 4: Install requirements

Step 5: Run the Application

streamlit run app.py

The app will open in your browser at http://localhost:8501


๐Ÿ“ฆ Project Structure

road-accident/
โ”œโ”€โ”€ app.py                          # Main Streamlit application
โ”œโ”€โ”€ preprocessing.py                # Data preprocessing functions
โ”œโ”€โ”€ model.py                        # Model loading and prediction
โ”œโ”€โ”€ data.py                         # Road/weather categories
โ”œโ”€โ”€ model.keras                     # Trained TensorFlow model (~100MB)
โ”œโ”€โ”€ pipeline.pkl                    # Preprocessing pipeline
โ”œโ”€โ”€ requirements.txt                # Pip dependencies
โ”œโ”€โ”€ environment.yml                 # Conda environment specification
โ”œโ”€โ”€ runtime.txt                     # Python version for deployment
โ”œโ”€โ”€ README.md                       # This file
โ””โ”€โ”€ DEPLOYMENT_CHECKLIST.md         # Deployment guide

๐Ÿ”ง Requirements

Python Packages (Auto-installed via Conda)

Package Version Purpose
streamlit latest Web framework for interactive UI
tensorflow 2.18.0 Deep learning framework for predictions
scikit-learn 1.2.2 Machine learning utilities
pandas 2.2.3 Data manipulation
numpy 1.26.4 Numerical computing
joblib 1.5.1 Model serialization
tf-keras 2.18.0 Keras API for TensorFlow
dill 0.3.8 Enhanced pickling for pipeline

System Requirements

  • OS: Windows, macOS, Linux
  • Python: 3.10
  • RAM: 2GB minimum (model loading)
  • Storage: ~500MB (model + dependencies)

๐ŸŽฏ Understanding the Game

Road Attributes

Each road scenario has these attributes:

Attribute Options
Road Type Highway, Urban, Rural
Number of Lanes 1-4
Curvature 0.0 - 1.0
Speed Limit 20-100 km/h
Lighting Daylight, Dim, Night
Weather Clear, Foggy, Rainy
Road Signs Yes/No
Public Road Yes/No
Time of Day Morning, Afternoon, Evening
Holiday Yes/No
School Season Yes/No

Model Prediction

The AI model analyzes these factors and predicts the expected number of accidents. Lower predictions = Safer road.


๐Ÿš€ Deployment

Option 1: Streamlit Cloud (Recommended - Already Live!)

The app is already deployed at: ๐ŸŒ Click Here to play

Option 2: Local Deployment

Run locally using the setup instructions above.

Option 3: Docker Deployment

docker build -t road-safety-game .
docker run -p 8501:8501 road-safety-game

See DEPLOYMENT_CHECKLIST.md for more deployment options.


๐ŸŽ“ How the Model Works

Training Data

  • Kaggle Road Accident Competition dataset
  • Features: Road conditions, weather, time factors
  • Target: Number of reported accidents

Preprocessing Pipeline

  • Categorical features โ†’ Ordinal encoding
  • Numerical features โ†’ Standard scaling
  • Passthrough of certain features

Model Architecture

  • TensorFlow/Keras neural network
  • Trained to predict accident count
  • Outputs: Expected number of accidents per scenario

๐Ÿ› Troubleshooting

Issue: Module not found error

# Ensure environment is activated
conda activate accident

# Verify installation
conda list

Issue: Model.keras not found

# Ensure you're in the project root directory
# File should be at: ./model.keras
ls model.keras  # macOS/Linux
dir model.keras # Windows

Issue: Slow predictions on first run

  • Normal behavior - model loads on startup (~2-3 seconds)
  • Subsequent predictions are cached and faster

Issue: Port 8501 already in use

streamlit run app.py --server.port 8502

๐Ÿค Contributing

Contributions welcome! Feel free to:

  • Report bugs
  • Suggest game improvements
  • Optimize model performance
  • Enhance UI/UX

๐Ÿ“ License

This project is part of the Kaggle Road Accident Competition.


๐Ÿ‘ค Author

Poushali-02


๐ŸŽ‰ Quick Start Summary

# 1. Clone
git clone https://github.com/Poushali-02/road-accident.git
cd road-accident

# 2. Create environment
conda env create -f environment.yml

# 3. Activate
conda activate accident

# 4. Run
streamlit run app.py

# 5. Play!
# Open browser at http://localhost:8501

Or play directly online: https://road-accident-vseuhvwqersrexrv7fxncg.streamlit.app/


๐Ÿ“Š Game Statistics Explained

  • ๐Ÿ† Total Score: Cumulative points across all rounds
  • ๐Ÿ“Š Round: Current round progress (e.g., 3/10)
  • ๐ŸŽฏ Target: Points needed to win (50)
  • ๐Ÿ”ฅ Winning Streak: Consecutive games won (resets on loss)

๐Ÿ”ฅ Tips to Win

  1. Make quick decisions - Speed = more points
  2. Focus on key factors - Weather, lighting, road type matter most
  3. Learn from feedback - See predictions after each answer
  4. Practice patterns - Similar conditions often have similar risk levels
  5. Beat the clock - Each second costs you points!

๐ŸŽฎ Game Flow Diagram

START โ†’ Generate 2 Scenarios โ†’ User Sees Roads โ†’ Timer Runs
   โ†“                                               โ†“
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ User Chooses Road โ”€โ”€โ”€โ”€โ”˜
                                  โ†“
                         Check if Correct?
                              โ†™      โ†–
                          YES        NO
                           โ†“          โ†“
                      Award Points  Award 0
                           โ†“          โ†“
                         Score โ‰ฅ 50?
                         โ†™        โ†–
                       YES         NO
                        โ†“           โ†“
                    YOU WIN!  Continue Playing
                        โ†“
                   Show Results
                   Winning Streak +1

Enjoy the game! Test your road safety intuition! ๐Ÿš—๐ŸŽฎ

Releases

No releases published

Packages

 
 
 

Contributors

Languages