from fastapi import FastAPI,UploadFile import shutil from fastapi.responses import HTMLResponse from fastapi.responses import FileResponse from fastapi.staticfiles import StaticFiles import app as predictor from PIL import Image, ImageFilter app = FastAPI() app.mount("/view", StaticFiles(directory="view", html=True), name="view") app.mount("/public", StaticFiles(directory="public", html=True), name="public") @app.get("/") def index() -> FileResponse: return FileResponse(path="./view/index.html", media_type="text/html") @app.post("/prediction/") async def predict(targetImage: UploadFile): path = f'public/{targetImage.filename}'# api/filesディレクトリを作成しておく with open(path, 'wb+') as buffer: shutil.copyfileobj(targetImage.file, buffer) im = Image.open(path) # todo quality指定できるようにする depth_image, mesh_path = predictor.predict(im, 3) print(mesh_path) return { "path":"public", "name":mesh_path }