-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (20 loc) · 635 Bytes
/
Copy pathapp.py
File metadata and controls
28 lines (20 loc) · 635 Bytes
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
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import JSONResponse
from PIL import Image
import io
import numpy as np
from src import Pipeline
app = FastAPI()
@app.get("/healthcheck/")
async def health_check():
return {"status": "ok"}
@app.post("/upload/")
async def upload_image(image: UploadFile = File(...)):
# Read the uploaded image
contents = await image.read()
# Open the image using PIL
pil_img = Image.open(io.BytesIO(contents))
open_cv_image = np.array(pil_img)
pil_img.close()
# Return the size as JSON
return JSONResponse(content=Pipeline()(open_cv_image))