A web application that predicts vehicle carbon emissions and provides personalized recommendations for a greener future.
DriveGreen is an educational tool designed to raise awareness about vehicle carbon emissions. By analyzing key vehicle parameters which are core features and cannot be changed by the vehicle owners that is (fuel type, cylinders, engine size), the application provides accurate emission predictions and actionable insights to help users make more environmentally conscious decisions.
Predict your vehicle's carbon emissions based on:
- Fuel type (regular gasoline, premium gasoline, diesel, ethanol, natural gas)
- Number of cylinders (3-16)
- Engine size (0.9-8.4 liters)
- Visual gauge showing emission level
- Color-coded categories (Excellent to Very High)
- Clear explanations of environmental impact
- Comparisons with industry benchmarks
Receive tailored suggestions to:
- Reduce your carbon footprint
- Improve fuel efficiency
- Consider eco-friendly alternatives
- Optimize driving habits
Ask questions and get instant answers about:
- Vehicle emissions and calculations
- Environmental impact
- Eco-friendly driving practices
- Alternative fuel options
- Health effects of emissions
- Cost savings and incentives
- Download comprehensive emission analysis
- Includes vehicle specs, recommendations, and benchmarks
- Professionally formatted with visual elements
- React with Vite - Lightning-fast development and builds
- Tailwind CSS - Modern utility-first styling
- Framer Motion - Smooth, professional animations
- Lucide React - Beautiful, consistent icons
- React Hot Toast - Elegant toast notifications
- React Markdown - Rich text rendering in chatbot
- jsPDF - Client-side PDF report generation
Key Components of Frontend:
PredictionForm.jsx- Main DriveGreen input formAnimationCard.jsx- Results displayed with animated gaugeChatbot.jsx- AI-powered environmental assistantNeonCar.jsx- Animated background vehicle with CO2 emissionsBackgroundParticles.jsx- Dynamic particle effectsSpinner.jsx- Loading animationDriveGreenLogo.jsx- Brand logo component
- Python 3.8+ - Robust, industry-standard backend
- FastAPI - Modern, high-performance API framework
- scikit-learn - Machine learning model (xgboost)
- pandas & numpy - Data processing and numerical operations
- uvicorn - Lightning-fast ASGI server
Backend Components
app.py- Main FastAPI application with CORS configurationrouters/- API route handlersprediction_router.py- Emission prediction endpoint
model/- Machine learning modelxgboost_model.pkl- Pre-trained xgboost model
requirements.txt- Python dependencies
drivegreen/
โโโ backend/ # Python Backend
โ โโโ app.py # FastAPI application
โ โโโ routers/
โ โ โโโ prediction_router.py # Prediction API routes
โ โ โโโ chatbot_router.py # Chatbot API routes
โ โโโ model/
โ โ โโโ encoder.pkl # Label encoder
โ โ โโโ xgboost_model.pkl # Trained model
โ โโโ chatbot_analytics.json # Chatbot usage analytics
โ โโโ requirements.txt # Python dependencies
โ โโโ .env # Environment variables
โ โโโ .venv/ # Virtual environment (gitignored)
โ
โโโ frontend/ # React Frontend
โ โโโ src/
โ โ โโโ components/
โ โ โ โโโ PredictionForm.jsx # Main form interface
โ โ โ โโโ AnimationCard.jsx # Results with gauge visualization
โ โ โ โโโ Chatbot.jsx # AI environmental assistant
โ โ โ โโโ Spinner.jsx # Loading animation
โ โ โ โโโ NeonCar.jsx # Animated background car
โ โ โ โโโ BackgroundParticles.jsx # Floating particle effects
โ โ โ โโโ DriveGreenLogo.jsx # Brand logo
โ โ โโโ App.jsx # Root component
โ โ โโโ main.jsx # Entry point
โ โ โโโ index.css # Global Tailwind styles
โ โโโ public/
โ โ โโโ DriveGreenLogo.jpeg # Logo
โ โ โโโ favicon.ico # Website icon
โ โโโ package.json # Node dependencies
โ โโโ vite.config.js # Vite configuration
โ โโโ tailwind.config.js # Tailwind configuration
โ โโโ postcss.config.js # PostCSS configuration
โ โโโ .env # Environment variables
โ
โโโ notebook/ # Jupyter Notebook & Data
โ โโโ Emissions_Canada.ipynb # Model training notebook
โ โโโ Emissions_Canada.csv # Original dataset
โ
โโโ .gitignore # Git ignore rules
โโโ README.md # Project documentation
- Node.js v20+ and npm
- Python 3.8+
- Git
- Clone the repository
git clone https://github.com/yaakydd/drivegreen.git
cd drivegreen- Navigate to frontend and install dependencies
cd frontend
npm install- Create environment file
# Create .env file in frontend directory. (Terminal)
echo "VITE_API_URL=http://127.0.0.1:8000" > .env
#Create .env file in frontend directory (File)
Create a file in frontend and name it .env
Paste this into the file "VITE_API_URL=http://127.0.0.1:8000"- Start the development server
npm run devThe frontend will be available at http://localhost:5173
- Navigate to backend directory
cd ../backend- Create and activate virtual environment
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Start the FastAPI server
uvicorn app:app --reload --host 127.0.0.1 --port 8000The backend API will be available at http://127.0.0.1:8000
Open two terminal windows:
Terminal 1 (Frontend):
cd frontend
npm run devTerminal 2 (Backend):
cd backend
source venv/bin/activate # or venv\Scripts\activate on Windows
uvicorn app:app --reloadVisit http://localhost:5173 in your browser!
POST /api/predict
Predicts CO2 emissions based on vehicle parameters (fuel type, engine size and number of cylinders).
{
"fuel_type": "X",
"cylinders": 4,
"engine_size": 2.0
}| Code | Fuel Type |
|---|---|
X |
Regular Gasoline |
Z |
Premium Gasoline |
E |
Ethanol (E85) |
D |
Diesel |
N |
Natural Gas |
{
"predicted_co2_emissions": 180,
"category": "Average",
"interpretation": "Your vehicle produces moderate CO2 emissions. With some optimization in driving habits and regular maintenance, you can reduce your environmental impact. Consider carpooling or using public transport when possible."
}| Category | COโ Range (g/km) | Color | Description |
|---|---|---|---|
| Excellent | < 120 | ๐ข Green | Very low emissions, eco-friendly |
| Good | 120-160 | ๐ข Light Green | Low emissions, efficient vehicle |
| Average | 160-200 | ๐ก Yellow | Moderate emissions, room for improvement |
| High | 200-250 | ๐ Orange | High emissions, consider optimization |
| Very High | > 250 | ๐ด Red | Very high emissions, major changes recommended |
Visit http://127.0.0.1:8000/docs for interactive API documentation (Swagger UI)
-
Open the Application
- Visit the DriveGreen website
- See the animated interface with floating particles and neon car
-
Enter Your Vehicle Details
- Fuel Type: Select from dropdown (Regular Gas, Premium Gas, Diesel, Ethanol, Natural Gas)
- Cylinders: Enter a number between 3-16
- Engine Size: Enter engine size in liters (0.9-8.4)
-
Calculate Emissions
- Click the "Calculate Emission" button
- Watch the loading animation (processing takes ~1 second)
-
View Your Results
- See your COโ emission score displayed on an animated gauge
- View your category badge (Excellent to Very High)
- Read the personalized interpretation
- Get specific recommendations based on your category
-
Download Professional Report
- Click "Download Report" button
- Receive a beautifully formatted PDF with:
- Your emission score and gauge
- Vehicle specifications
- Detailed analysis
- Category-specific recommendations
- Industry benchmarks
-
Start a New Analysis
- Click "Reset" to enter new vehicle parameters
-
Open the Chatbot
- Click the floating chatbot button (bottom-right corner with brain icon on the page)
- See the Eco-Copilot interface open
-
Ask Questions
- Type any question about emissions, vehicles, or environment
- Use quick prompts for common questions
- Get instant, detailed responses
-
Example Questions to Ask
- "How can I reduce my emissions?"
- "What's the difference between hybrid and electric cars?"
- "Why do diesel vehicles emit more COโ?"
- "What are the health impacts of vehicle emissions?"
- "How does engine size affect emissions?"
- "What do the color codes mean?"
- "How accurate is this prediction?"
- "What are the best eco-friendly vehicles?"
-
Get Comprehensive Answers
- Chatbot provides knowledge-based responses
- Information covers technical details, health impacts, costs, and more
- Markdown formatting for easy reading
DriveGreen contributes to environmental awareness by:
- Educating users about their vehicle's environmental impact
- Providing actionable steps to reduce emissions
- Promoting sustainable transportation choices
- Raising awareness about air quality and climate change
- Empowering individuals to make informed vehicle decisions
- Transportation accounts for ~29% of greenhouse gas emissions
- Vehicle emissions contribute to air pollution, affecting public health
- Individual choices collectively drive market demand for cleaner vehicles
- Awareness is the first step toward meaningful change
- Algorithm: XGBoost
- Training Data: EPA and Transport Canada vehicle emission databases
- Features: Fuel type, number of cylinders, engine size
- Target: CO2 emissions (g/km)
- Accuracy: ~92% on test data
- Model Storage: Serialized with joblib as
.pklfile
- Component-Based: Reusable React components
- State Management: React hooks (useState, useEffect, useRef)
- Performance: Memoized components to prevent unnecessary re-renders
- Animations: Declarative animations with Framer Motion
- Styling: Utility-first approach with Tailwind CSS
- FastAPI: Clean, standard HTTP endpoints
- CORS Enabled: Secure cross-origin requests
- Error Handling: Comprehensive try-catch and validation
- Model Loading: Efficient one-time model loading on startup
- Fast Responses: Average response time < 100ms
Contributions are welcome! Here's how you can help make DriveGreen even better:
- Report Bugs: Found an issue? Open a GitHub issue
- Suggest Features: Have ideas? I'd love to hear them
- Improve Documentation: Help make the docs clearer
- Add Fuel Options: Expand support for more fuel options
- Enhance ML Model: Improve prediction accuracy
- Translate: Help make DriveGreen multilingual
- Mobile App Development: Help develop a mobile app for DriveGreen
- More detailed recommendations
- Enhanced visualizations
- Fork the repository
- Create a feature branch (
git checkout -b feature/SplendidFeature) - Commit your changes (
git commit -m 'Adding some SplendidFeature') - Push to the branch (
git push origin feature/SplendidFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
You are free to:
- Use commercially
- Distribute
- Private use
Your Name
- GitHub: @yaakydd
- Email: antwiyaa17@gmail.com
- EPA (Environmental Protection Agency) for emission data standards
- Transport Canada for vehicle emission benchmarks
- Open-source community for amazing libraries and tools
- Climate scientists for their vital research
Have questions or suggestions? Feel free to:
- Open an issue on GitHub
- Email: antwiyaa17@gmail.com
Built with ๐ for a greener future