Road Safety AI Game - Test your intuition about road safety with an AI-powered prediction model!
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.
- Click "START GAME" - A timer begins
- Analyze two road scenarios with different conditions (weather, lighting, road type, etc.)
- Choose the safer road before time runs out
- Earn points based on speed - Quick answers = more points
- Win at 50 points - Complete 10 rounds or reach 50 points first
- Track your winning streak - How many games can you win in a row?
- 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
- โฑ๏ธ 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
๐ Play Now: https://road-accident-vseuhvwqersrexrv7fxncg.streamlit.app/
The game is live and ready to play! No installation needed - just click and start playing.
- Conda (Anaconda or Miniconda installed)
- Git (for cloning the repository)
- Python 3.10 (specified in environment.yml)
git clone https://github.com/Poushali-02/road-accident.git
cd road-accidentUsing the provided environment.yml:
conda env create -f environment.ymlThis will create a conda environment named accident with all required dependencies at their exact versions.
conda activate accidentYou should see (accident) in your terminal prompt.
streamlit run app.pyThe app will open in your browser at http://localhost:8501
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
| 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 |
- OS: Windows, macOS, Linux
- Python: 3.10
- RAM: 2GB minimum (model loading)
- Storage: ~500MB (model + dependencies)
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 |
The AI model analyzes these factors and predicts the expected number of accidents. Lower predictions = Safer road.
The app is already deployed at: ๐ Click Here to play
Run locally using the setup instructions above.
docker build -t road-safety-game .
docker run -p 8501:8501 road-safety-gameSee DEPLOYMENT_CHECKLIST.md for more deployment options.
- Kaggle Road Accident Competition dataset
- Features: Road conditions, weather, time factors
- Target: Number of reported accidents
- Categorical features โ Ordinal encoding
- Numerical features โ Standard scaling
- Passthrough of certain features
- TensorFlow/Keras neural network
- Trained to predict accident count
- Outputs: Expected number of accidents per scenario
# Ensure environment is activated
conda activate accident
# Verify installation
conda list# Ensure you're in the project root directory
# File should be at: ./model.keras
ls model.keras # macOS/Linux
dir model.keras # Windows
- Normal behavior - model loads on startup (~2-3 seconds)
- Subsequent predictions are cached and faster
streamlit run app.py --server.port 8502Contributions welcome! Feel free to:
- Report bugs
- Suggest game improvements
- Optimize model performance
- Enhance UI/UX
This project is part of the Kaggle Road Accident Competition.
Poushali-02
- GitHub: https://github.com/Poushali-02/road-accident
- Repository: road-accident (Kaggle & Stack Overflow competition)
# 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:8501Or play directly online: https://road-accident-vseuhvwqersrexrv7fxncg.streamlit.app/
- ๐ 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)
- Make quick decisions - Speed = more points
- Focus on key factors - Weather, lighting, road type matter most
- Learn from feedback - See predictions after each answer
- Practice patterns - Similar conditions often have similar risk levels
- Beat the clock - Each second costs you points!
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! ๐๐ฎ