This project hosts a Flask server that serves predictions from multiple models.
-
Set up a Virtual Environment
python -m venv venv
-
Activate the Virtual Environment
- On macOS/Linux:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On macOS/Linux:
-
Install Dependencies
pip install -r requirements.txt
-
Run the Server
flask run
-
Create a New File inside the
models/Directory -
Define a Function with the
@register_modelDecoratorExample:
from .registry import register_model from PIL import Image import numpy as np @register_model("xo") # Replace "xo" with your desired action name def xo_model(img: Image.Image) -> str: result = np.array(detect_tic_tac_toe(img)).flatten().tolist() m = {"X": 1, "O": 2, "-": 0} logger.info(f"Result: {result}") return ",".join([str(m[item]) for item in result])
- The function must:
- Take a
PIL.Image.Imageas input. - Return a comma-separated
stringas output.
- Take a
- The function must:
-
Model Files
- If your model requires any additional files, add them to the
model_files/directory. - Use clear and descriptive file names based on your model's purpose.
Example directory structure:
model_files/ ├── xo.pt ├── some_other_model_file.pt - If your model requires any additional files, add them to the
- Method:
POST - Endpoint:
/predict - Query Parameter:
action(the action name you registered) - Request Body: raw image binary buffer (NOT multipart/form-data)