api_server.py: moved from frontend/main.py, made roughly functional
This commit is contained in:
parent
3f48276aed
commit
8f0c3a32b8
@ -1,6 +1,7 @@
|
||||
from io import BytesIO
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, File, UploadFile
|
||||
from pydantic import BaseModel
|
||||
|
||||
import numpy as np
|
||||
@ -8,7 +9,9 @@ from cv2 import cv2
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
from ..nets import Model
|
||||
from nets import Model
|
||||
from PIL import Image
|
||||
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
@ -23,11 +26,6 @@ app = FastAPI()
|
||||
# kommt ctd überhaupt mit was anderem klar?
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
price: float
|
||||
is_offer: Optional[bool] = None
|
||||
|
||||
|
||||
class IrImage(BaseModel):
|
||||
image: np.array
|
||||
@ -96,16 +94,18 @@ def inference_ctd(left, right, model, n_iter=20):
|
||||
|
||||
|
||||
@app.put("/ir")
|
||||
def read_ir_input(ir_image: IrImage):
|
||||
pred_disp = inference_ctd(ir_image.image, reference_pattern)
|
||||
async def read_ir_input(file: UploadFile = File(...)):
|
||||
try:
|
||||
img = np.array(Image.open(BytesIO(await file.read())))
|
||||
except Exception as e:
|
||||
return {'error': 'couldn\'t read file', 'exception': e}
|
||||
print(img.shape)
|
||||
if len(img.shape) == 2:
|
||||
img = np.stack((img for _ in range(3)))
|
||||
pred_disp = inference_ctd(np.array(img), reference_pattern, None)
|
||||
return {"pred_disp": pred_disp}
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
def read_item(item_id: int, q: Optional[str] = None):
|
||||
return {"item_id": item_id, "q": q}
|
||||
|
||||
|
||||
@app.put("/items/{item_id}")
|
||||
def update_item(item_id: int, item: Item):
|
||||
return {"item_price": item.price, "item_id": item_id}
|
||||
@app.get('/')
|
||||
def main():
|
||||
return {'test': 'abc'}
|
Loading…
Reference in New Issue
Block a user