|
from fastapi import FastAPI, HTTPException
|
|
import random
|
|
from pydantic import BaseModel
|
|
from typing import List
|
|
from utils import decode_image
|
|
from mediapipe_preprocess import mediapipe_process
|
|
from model_predict import model_predict
|
|
import numpy as np
|
|
|
|
class Item(BaseModel):
|
|
text: str
|
|
number: int | None = None
|
|
|
|
class RecordFrames(BaseModel):
|
|
images: List[str]
|
|
|
|
app = FastAPI()
|
|
|
|
@app.get("/")
|
|
def return_hello():
|
|
return {"text":"Hello from server"}
|
|
|
|
@app.get("/random")
|
|
def return_random():
|
|
return {"random number":int(random.random()*1000)}
|
|
|
|
@app.post("/receive")
|
|
def return_received(item: Item):
|
|
return {"text":item.text,
|
|
"number":item.number}
|
|
|
|
@app.post("/predict")
|
|
def return_predict(record: RecordFrames):
|
|
if not record.images:
|
|
raise HTTPException(status_code=400, detail="No images provided")
|
|
|
|
frames = [np.array(decode_image(img)) for img in record.images]
|
|
keypoints = mediapipe_process(frames)
|
|
label = model_predict(keypoints)
|
|
return {"label":label} |