File size: 795 Bytes
2dfe23c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import os
from PIL import Image
import numpy as np
from fastapi import FastAPI, UploadFile

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
from image_tagger.main import tagger

app = FastAPI(title="Face Recognition")


@app.get("/")
def display():
    return "Welcome to Image Tagger Api"


@app.post("/predict")
def predict(file: UploadFile):
    img = Image.open(file.file)
    img = np.array(img)
    img = np.transpose(img, (2, 0, 1)).astype(dtype=np.float32)
    img /= 255.0
    boxes, matrixs, keypoints, results = tagger(img)

    return {
        "predictions": results,
        "boxes": boxes.tolist(),
        "matrixs": [matrix.tolist() for matrix in matrixs],
        "keypoints": [keypoint.tolist() for keypoint in keypoints],
    }