A web application that identifies tree species from leaf images using a deep learning model. The system uses a server-side API architecture to avoid browser compilation issues with large TensorFlow.js models.
- Python 3.12 (or compatible version)
- Node.js and npm installed
- Trained model files:
train/model.keras- The trained Keras modeltrain/class_mapping.json- Class name mapping file
cd server
python -m pip install -r requirements.txtnpm installYou need to run both the backend server and frontend in separate terminals.
Open a terminal/PowerShell window and run:
cd server
.\start_server.ps1Or manually:
cd server
python app.pyWait for this message:
✅ Server ready! Listening on http://localhost:5000
Keep this terminal open! The server must stay running.
Open a different terminal/PowerShell window and run:
npm run devWait for this message:
VITE v5.x.x ready in xxx ms
➜ Local: http://localhost:8080/
- Open your browser to
http://localhost:8080 - Click "Choose File"
- Select a tree leaf image
- View the classification results!
Before uploading an image, you can test if the server is working:
Open in your browser: http://localhost:5000/health
You should see:
{"status":"ok","message":"Tree classification API is running"}- Frontend: React + TypeScript + Vite (runs on port 8080)
- Backend: Flask API server (runs on port 5000)
- Model: Keras MobileNetV2 model (160x160 input, 10 tree classes)
- Communication: Vite proxy routes
/api/*to Flask server
- User uploads image → Frontend receives file
- Frontend sends to API →
POST /api/predict(via Vite proxy) - Vite proxies request → Forwards to
http://127.0.0.1:5000/predict - Flask server processes → Loads model, preprocesses image (160x160), runs prediction
- Server returns results → JSON with className, confidence, top3, allProbabilities
- Frontend displays → Shows results on
/resultspage
- Make sure you ran
.\start_server.ps1in theserverfolder - Check that you see "Server ready!" message
- The server terminal must stay open
- Test the server directly:
http://localhost:5000/health
- This is usually an ad blocker issue
- Try disabling your ad blocker for localhost
- Or test in an incognito/private window with extensions disabled
- The Vite proxy should prevent this, but some ad blockers are aggressive
- Make sure BOTH server and frontend are running
- Check that server shows "Listening on http://localhost:5000"
- Verify frontend is running on port 8080
- Try the health check URL in your browser first
- Check that
train/model.kerasexists - Check that
train/class_mapping.jsonexists - Verify the file paths in
server/app.pymatch your structure
- Frontend: Port 8080 (change in
vite.config.ts) - Backend: Port 5000 (change in
server/app.pyline 126) - If you change ports, update both the Flask port and the Vite proxy target URL
- Make sure Python 3.12 is installed
- Install dependencies:
cd server && python -m pip install -r requirements.txt - Check that model files exist in
train/directory
Health check endpoint
- Response:
{"status": "ok", "message": "Tree classification API is running"}
Predict tree species from image
- Request:
multipart/form-datawithimagefile - Response:
{
"className": "Red_Maple",
"confidence": 0.95,
"top3": [
{"className": "Red_Maple", "confidence": 0.95},
{"className": "White_Oak", "confidence": 0.03},
{"className": "Tulip_Poplar", "confidence": 0.02}
],
"allProbabilities": [...]
}- The server loads the model once on startup (takes a few seconds)
- Predictions typically take 1-2 seconds per image
- The model supports 10 tree species classes
- Both terminals (server and frontend) must stay running while using the app