This repository contains the backend code of www.name-to-ethnicity.com.
git clone [email protected]:name-ethnicity-classifier/backend.git
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
Create a file called ".env" in the root folder. Add the following variables (these are dummy values which can be used during development but DON'T use them for deployment):
# Variables for REST API
FLASK_RUN_PORT=8080
FLASK_APP=src/app.py
# Variables for JWT
JWT_SECRET=supersecret
JWT_EXPIRATION_DAYS=30
# Variables for dev. database
POSTGRES_HOST=localhost
POSTGRES_USER=postgres
POSTGRES_PASSWORD=pwd123
POSTGRES_DB=n2e-db
POSTGRES_PORT=5432
ADMINER_PORT=6060
# Variables for inference
BATCH_SIZE=64
MAX_NAMES=1000
python3 -m flask run
The server runs now at "localhost:8080".
If you need to develop CRUD features, you'll need to run a Postgres database in parallel for testing and development.
You can install it from here.
Create a file called ".env" in the "dev-database" folder. Add the following variables (these are dummy values which can be used during development but DON'T use them for deployment): Make sure that the ".env" in the root folder has the same values for the DB variables as this ".env"!
POSTGRES_HOST=localhost
POSTGRES_USER=postgres
POSTGRES_PASSWORD=pwd123
POSTGRES_DB=n2e-db
POSTGRES_PORT=5432
ADMINER_PORT=6060
sh ./run_dev_db.sh
If you need to reinitialize the database (ie. removing existing containers and volumes), run:
sh ./run_dev_db.sh --remove
This script will run the docker-compose file inside the ./dev_database
. If you encount any errors that point to missing Postgres environment variables, you might need to copy the .env
into the ./dev_database
.
The port of the database and Adminer UI depend on what you specified in the .env file, but by default the database will be accessible on localhost:5432
and the Adminer UI on localhost:6061
.
This database is persistent, so when you add data it will stay until you delete it.