A web application for browsing and searching electric vehicles with natural language processing capabilities.
- Features
- Technology Stack
- Prerequisites
- Installation
- Configuration
- Running the Application
- Deployment
- Project Structure
- API Endpoints
- Testing
- Troubleshooting
- Browse electric vehicles with detailed specifications
- Natural language search (e.g., "affordable SUV under 50000")
- Filter by price, range, body type, drivetrain, and seats
- Save vehicles for later comparison
- Responsive design for mobile and desktop
- Semantic search using sentence-transformers
- Rate limiting and session management
- Result caching for better performance
Backend
- FastAPI - Web framework
- Pydantic - Data validation and settings
- Jinja2 - Template engine
- Uvicorn - ASGI server
- NumPy - Numerical operations
- Sentence Transformers - Semantic search (optional)
- CacheTools - In-memory caching
Frontend
- JavaScript (vanilla)
- CSS3 (Grid and Flexbox)
- Lazy loading for images
Deployment
- Railway or Vercel
- Pytest for testing
- Python 3.9 or higher
- pip (usually included with Python)
- Git (optional)
Check your Python version:
python --versionClone the repository:
git clone https://github.com/ginesbal/ev_chatbotmodel.git
cd ev_chatbotmodelCreate and activate a virtual environment:
Windows:
python -m venv venv
venv\Scripts\activatemacOS/Linux:
python -m venv venv
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtCreate a .env file in the root directory with the following settings:
EVISION_SECRET_KEY=your-secret-key-here
DEBUG=false
SEMANTIC_SEARCH=auto
RATE_LIMIT_PER_MIN=60
Generate a secret key:
python -c "import secrets; print(secrets.token_urlsafe(32))"Configuration variables:
EVISION_SECRET_KEY- Session encryption key (required for production)DEBUG- Enable verbose logging and disable rate limitingSEMANTIC_SEARCH-autofor NLP search,offfor keyword-onlyRATE_LIMIT_PER_MIN- Max requests per IP per minute
Start the development server:
uvicorn app.main:app --reloadThe application will be available at http://127.0.0.1:8000
For production:
uvicorn app.main:app --host 0.0.0.0 --port 8000For serverless deployment (Vercel):
uvicorn api.index:app --reloadStop the server with CTRL+C. Deactivate the virtual environment with deactivate.
Recommended platform with automatic deployments.
- Create an account at railway.app
- Click "New Project" > "Deploy from GitHub repo"
- Select the
ev_chatbotmodelrepository - Add environment variables (especially
EVISION_SECRET_KEY) - Railway will build and deploy automatically
Deploy with:
vercel --prodConfiguration files: vercel.json and api/index.py
Requirements: Python 3.9+, systemd or supervisor, Nginx/Apache
Example systemd service:
[Unit]
Description=EVision Advisor
After=network.target
[Service]
User=www-data
WorkingDirectory=/path/to/ev_chatbotmodel
Environment="PATH=/path/to/ev_chatbotmodel/venv/bin"
ExecStart=/path/to/ev_chatbotmodel/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.targetev_chatbotmodel/
├── api/
│ ├── index.py # Serverless entry point (Vercel/AWS Lambda)
│ └── __pycache__/
├── app/
│ ├── __init__.py
│ ├── config.py # Application configuration and settings
│ ├── main.py # Main FastAPI application
│ ├── obsv.py # Observability and logging setup
│ ├── rate_limit.py # Rate limiting middleware
│ ├── models/
│ │ ├── __init__.py
│ │ └── schemas.py # Pydantic models for data validation
│ ├── routes/
│ │ ├── __init__.py
│ │ ├── health.py # Health check endpoint
│ │ ├── home.py # Home page route
│ │ ├── saved.py # Saved vehicles management
│ │ └── search.py # Search and filtering logic
│ ├── services/
│ │ ├── __init__.py
│ │ ├── nlp.py # Natural language processing
│ │ ├── repository.py # Data access layer
│ │ └── search_service.py # Search and ranking algorithms
│ └── utils/
│ ├── __init__.py
│ └── evtable.py # Electric vehicle data utilities
├── static/
│ ├── css/ # Stylesheets
│ ├── js/ # JavaScript files
│ ├── images/ # Images and icons
│ └── fonts/ # Web fonts
├── templates/
│ ├── base.html # Base template with common layout
│ ├── home.html # Home page template
│ ├── browse.html # Browse vehicles template
│ ├── index.html # Landing page
│ └── includes/ # Reusable template fragments
├── tests/
│ ├── conftest.py # Pytest configuration and fixtures
│ ├── test_cases.yaml # Test case definitions
│ ├── test_search_suite.py # Search functionality tests
│ ├── test_saved_endpoints.py # Saved vehicles tests
│ └── ... # Additional test files
├── docs/ # Documentation and screenshots
├── .env # Environment variables (not in repository)
├── .gitignore # Git ignore rules
├── requirements.txt # Python dependencies
├── Procfile # Process file for Railway deployment
├── railway.json # Railway configuration
├── runtime.txt # Python runtime version
├── vercel.json # Vercel configuration
├── RAILWAY_DEPLOYMENT.md # Railway deployment guide
└── README.md # This file
Key Files:
app/main.py- Main application and route registrationapp/config.py- Configuration and settingsapp/services/search_service.py- Search logic and rankingapp/services/nlp.py- Semantic search implementationapp/routes/- HTTP endpoint handlersrequirements.txt- Python dependenciesProcfile- Deployment configuration
GET /
Home page with vehicle browser
GET /health
Health check - returns {"ok": true}
GET /search
Search vehicles with query parameters:
q- Search queryprice_max- Maximum price (CAD)range_min- Minimum range (km)body_type- sedan, suv, truck, etc.seats- Minimum seating capacitydrivetrain- all-wheel-drive, rear-wheel-drive, front-wheel-drivesort- relevance, price, range, efficiency
POST /saved/add
Add vehicle to saved list - Body: {"vin": "vehicle-vin"}
POST /saved/remove
Remove vehicle from saved list - Body: {"vin": "vehicle-vin"}
GET /saved
View saved vehicles page
GET /saved/data
Get saved vehicles as JSON
Response codes:
- 200 - Success
- 400 - Invalid parameters
- 404 - Not found
- 429 - Rate limit exceeded
- 500 - Server error
Run all tests:
pytestRun specific test file:
pytest tests/test_search_suite.pyRun with coverage:
pytest --cov=app --cov-report=htmlTest files:
test_search_suite.py- Search functionalitytest_saved_endpoints.py- Saved vehiclestest_parser_filters.py- Query parsingtest_ranking_brand_model.py- Ranking algorithmstest_sorting_determinism.py- Sort consistencytest_sort_stability.py- Sort stabilitytest_saved_counts_parity.py- Data consistency
Test configuration is in tests/conftest.py and tests/test_cases.yaml.
ModuleNotFoundError
Activate virtual environment and reinstall dependencies:
pip install -r requirements.txtPort already in use
Use a different port:
uvicorn app.main:app --reload --port 8001Static files not loading
Verify static/ directory exists and STATIC_DIR config is correct.
Semantic search not working
Check SEMANTIC_SEARCH setting. Model download requires ~80MB disk space.
Session data lost
Set EVISION_SECRET_KEY in .env file.
Rate limit errors
Set DEBUG=true in .env to disable rate limiting.
Tests failing
Verify dependencies and test data files exist:
pip install -r requirements.txt
pytest --versionCheck app.log for error details.