This app is built on the machine learning toolbox ml-morph. This app has a pre-trained model to predict 34 landmarks on lizard anole x-rays.
To learn more about the ml-morph toolbox:
Porto, A. and Voje, K.L., 2020. ML‐morph: A fast, accurate and general approach for automated detection and landmarking of biological structures in images. Methods in Ecology and Evolution, 11(4), pp.500-512.
- Frontend: Located in
frontend/, built with React. - Backend: Located in
backend/, powered by Flask.
Port availability may vary depending on your device. To specify a custom port for the backend, create a .env file in the root directory with the following content:
API_PORT=3000 # your desire port number
If no port is specified, the default is 5000.
- Navigate to the
backendfolder. - Since the predictor is too big for this platform, download here: https://gatech.box.com/s/qky0pu7hd3y0b8okvl3r7zgfiaj961vb
- Paste the predictor into the backend folder
- Install dependencies:
pip install -r requirements.txt - Run the Flask server:
python app.py
- Install node.js and add it to the PATH.
- Navigate to the
frontendfolder. - Install dependencies:
npm install - Start the React app:
npm run dev
If you want to make your local development server accessible from the internet: https://ngrok.com/docs/getting-started/
-
Install ngrok:
- Download from https://ngrok.com/download
- Or
brew install ngrok(macOS)
-
Configure ngrok:
- Register a free account with ngrok
- Add your auth token
ngrok config add-authtoken YOUR_AUTH_TOKEN
-
Create/Update
.envfile (mentioned above) with the followingVITE_ALLOWED_HOSTS=your-subdomain.ngrok-free.appReplace
your-subdomainwith your actual ngrok subdomain (e.g., "8e41-123-45-67-89.ngrok-free.app") -
Start ngrok tunnel (after starting your frontend server):
ngrok http 5173 # Use your frontend port number -
Copy the generated ngrok URL and update your
.envfile with this domain.
Note: The ngrok URL will change each time you restart ngrok unless you have a paid account with a fixed subdomain.
API_PORT=3000 # your desire port number
VITE_ALLOWED_HOSTS=your-subdomain.ngrok-free.app
- Open a terminal and activate the backend with the instructions from above
- Open another terminal and activate the frontend with the instructions from above
- Navigate to http://localhost:5000
- Hit upload on the webpage and select the picture from the folder sample_image in the project directory
- Notice output.xml, output.tps, output.csv appear in project directory
- Image should appear in the web browser:
- Landmarks on image can be moved to fix predictions
- Image can be viewed in three ways: original upload, color contrasted or inverted color
- Image can be downloaded for records
To test the complete application locally using Docker:
-
Ensure Docker Desktop is installed and running
-
Make sure the predictor file (
better_predictor_auto.dat) is in thebackend/directory -
Build and run the Docker container:
# Build the Docker image docker build -t lizardcv:latest . # Run the container docker run -d -p 5000:5000 --name lizard-app-test lizardcv:latest
-
Access the application at http://localhost:5000
-
To stop and remove the container when done:
docker stop lizard-app-test docker rm lizard-app-test
For development, you can run the frontend and backend separately:
-
Start the backend server:
cd backend python app.py -
In a separate terminal, start the frontend:
cd frontend npm start -
Access the frontend at http://localhost:3000
The project includes a PowerShell script (deploy.ps1) for simplified deployment:
- Open PowerShell in the project root
- Run the script:
.\deploy.ps1
- Choose from the menu:
- Option 1: Build & Test Docker Locally
- Option 2: Deploy to Azure
- Option 3: Clean Up Azure Resources
To deploy manually to Azure:
-
Login to Azure:
az login -
Create a resource group:
az group create --name lizard-app-rg --location eastus -
Create Azure Container Registry:
az acr create --resource-group lizard-app-rg --name [your-registry-name] --sku Basic -
Build and push the Docker image:
az acr build --resource-group lizard-app-rg --registry [your-registry-name] --image lizardcv:latest . -
Create App Service plan:
az appservice plan create --name lizard-app-plan --resource-group lizard-app-rg --sku B1 --is-linux -
Create and configure the web app:
az webapp create --resource-group lizard-app-rg --plan lizard-app-plan --name [your-app-name] --deployment-container-image-name [your-registry-name].azurecr.io/lizardcv:latest
-
Predictor File: The machine learning model file (
better_predictor_auto.dat) is required but not included in the repository due to its size. You must download it separately and place it in the backend directory. -
Docker Memory Requirements: The Docker container may require significant memory. If you encounter container crashes during build or runtime, try increasing Docker's allocated memory in settings.
-
Container Registry Authentication: The current deployment script sets up managed identity for ACR Pull role, but this configuration may require additional permissions adjustments in some Azure environments.
-
Processing Large Files: The B1 App Service tier may be insufficient for processing multiple or large X-ray images. Consider upgrading to at least a B2 or P1v2 tier for production workloads.
-
Gunicorn Configuration: The current Gunicorn configuration in
gunicorn.conf.pyis set to bind to port 50505, but the Dockerfile and App Service expect port 5000. This discrepancy may cause connectivity issues when deployed to Azure. Modify thegunicorn.conf.pyfile to use port 5000 before deployment:# In gunicorn.conf.py bind = "0.0.0.0:5000" # Change from 50505 to 5000
-
Cold Start Issues: Azure App Service containers may experience cold start delays. The initial load of the application might take up to a minute due to the size of the ML models being loaded.
- Missing predictor file error: Download the predictor file from the link above and place it in the backend directory.
- Docker build failure: Ensure Docker has enough allocated memory (at least 4GB recommended).
- Frontend not loading: Check browser console for CORS errors; ensure the backend API URL is correctly set.
- Image processing errors: Verify the uploaded image format is supported (JPG, PNG, TIF, BMP).
- Azure deployment issues: Check Azure logs with
az webapp log tail --resource-group lizard-app-rg --name [your-app-name]
