This project now uses a two-service architecture so your actual trained ML/DL models are used in production.
- Next.js frontend on Vercel
- Python FastAPI model backend on Render or Railway
- Browser -> Next.js app
- Next.js API route app/api/analyze/route.ts
- Python backend backend/main.py
- Model artifacts from models
The backend loads and runs these trained models:
- Naive Bayes (.pkl)
- SVM (.pkl)
- LSTM (.h5)
- CNN-LSTM (.h5)
Model files are expected in models:
- nb_model.pkl
- svm_model.pkl
- tokenizer.pkl
- metrics.pkl
- lstm_model.h5
- cnn_lstm_model.h5
If they do not exist, generate them using backend/train.py.
- Calibrated per-model thresholds are learned and saved during training.
- Backend applies these thresholds during inference instead of fixed 0.50.
- Short-text guard marks very short input as low-reliability.
- Exact 2/4 split is treated as non-deterministic.
You can use either backend-prefixed commands or root compatibility commands.
Compatibility commands from project root:
python -m pip install -r requirements.txt
python train.py
python -m uvicorn main:app --host 0.0.0.0 --port 8000- Train models (once)
.\.venv310\Scripts\python.exe backend/train.pyTraining defaults to full IMDB split. For faster experiments:
set FAST_DEV=1
.\.venv310\Scripts\python.exe backend/train.py- Start Python backend
.\.venv310\Scripts\python.exe -m pip install -r backend/requirements.txt
.\.venv310\Scripts\python.exe -m uvicorn backend.main:app --host 0.0.0.0 --port 8000- Configure frontend env
copy .env.example .env.localSet in .env.local:
PYTHON_BACKEND_URL=http://127.0.0.1:8000- Start frontend
npm install
npm run devOpen http://localhost:3000.
- Create a new web service from this repo, using backend as root.
- Build command:
pip install -r requirements.txt- Start command:
uvicorn main:app --host 0.0.0.0 --port $PORT- Set
MODELS_DIRif your artifacts are mounted elsewhere. - Ensure model files are present at deploy time.
- Import the same repository in Vercel.
- Add env variable in Vercel project settings:
PYTHON_BACKEND_URL=https://your-backend-service-url- Deploy.
- Vercel hosts the web layer, not TensorFlow-heavy Python inference.
- Keep model artifacts with backend hosting, not in frontend runtime.
- If model files are too large for regular git, use Git LFS or object storage.