File size: 1,158 Bytes
fba2ed6
 
 
 
 
8e22504
fba2ed6
 
 
 
 
8e22504
 
 
 
 
 
 
fba2ed6
 
 
 
 
 
 
8865468
fba2ed6
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
from fastapi import FastAPI,UploadFile
import shutil
from fastapi.responses import HTMLResponse
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from starlette.middleware.cors import CORSMiddleware 
import app as predictor
from PIL import Image, ImageFilter

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["'GET'","'POST'"],
    allow_headers=["*"]
)

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
  }