Production-ready FastAPI web app for pest photo classification and field guidance.
python3 -m venv --system-site-packages .venv
.venv/bin/python -m pip install -r requirements.txt
cp .env.example .env
.venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8000 --reloadOpen http://127.0.0.1:8000.
The backend reads GEMINI_API_KEY from .env in the project root. Without a key, scans still work and use the built-in pest knowledge fallback. With a key, the app uses GEMINI_MODEL, defaulting to gemini-2.5-flash.
User accounts are stored in azira.db by default through SQLAlchemy. The app uses email/password registration and login, validates email format, and protects scan uploads with bearer sessions.
For production, use Neon PostgreSQL or another managed Postgres service and set DATABASE_URL plus a strong AZIRA_SECRET_KEY.
Create a Neon project, copy its pooled or direct connection string, and use it as:
DATABASE_URL=postgresql://NEON_USER:NEON_PASSWORD@NEON_HOST/NEON_DATABASE?sslmode=requireThe app automatically normalizes postgresql:// and postgres:// URLs to SQLAlchemy's postgresql+psycopg:// driver format.
Set these deployment variables too:
GEMINI_API_KEY=YOUR_GEMINI_API_KEY_HERE
GEMINI_MODEL=gemini-2.5-flash
AZIRA_SECRET_KEY=YOUR_LONG_RANDOM_SECRET_HERE
AZIRA_MODEL_PATH=data/fastvit_t12_pest_float32.tflite
AZIRA_DEVICE=cpu
DB_POOL_SIZE=5
DB_MAX_OVERFLOW=10
DB_POOL_RECYCLE_SECONDS=300
AZIRA_AUTO_CREATE_TABLES=trueGenerate a secret with:
.venv/bin/python -c "import secrets; print(secrets.token_urlsafe(64))"Check the Neon connection after setting DATABASE_URL:
.venv/bin/python - <<'PY'
from azira.database import engine
with engine.connect() as conn:
print(conn.exec_driver_sql("select current_database()").scalar())
PYThe app serves the float32 TFLite model at data/fastvit_t12_pest_float32.tflite with ai-edge-litert.
- 15 pest classes
- 224px RGB image input
- float32 NHWC input tensor
- float32 logits output tensor
GET /api/health- model and Gemini status.GET /api/classes- pest classes and display names.POST /api/analyze- multipart image upload with optionalcropandregionfields.
Chemical guidance is intentionally conservative: the app avoids fabricated brands, prices, and exact dosages. Always confirm local registration, labels, PPE, and pre-harvest intervals.