-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_server.py
More file actions
35 lines (28 loc) · 1.23 KB
/
Copy pathmain_server.py
File metadata and controls
35 lines (28 loc) · 1.23 KB
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
import json
import os
from fastapi import FastAPI, File, UploadFile, Request, Form
import aiofiles
from core.logic.recognizer import Recognizer
app = FastAPI()
@app.post("/recognize_yolo/")
async def recognize_yolo(file: UploadFile, template: str= Form(...)):
try:
json_data = json.loads(template)
except json.decoder.JSONDecodeError:
return {"message": "JSON ERROR"}
filename = os.path.join(os.path.dirname(__file__), 'core', 'media', file.filename)
async with aiofiles.open(filename, 'wb') as out_file:
content = await file.read() # async read
await out_file.write(content) # async write
return Recognizer.recognize_yolo(json_data, filename)
@app.post("/recognize_vision_ai/")
async def recognize_vision_ai(file: UploadFile, template: str= Form(...)):
try:
json_data = json.loads(template)
except json.decoder.JSONDecodeError:
return {"message": "JSON ERROR"}
filename = os.path.join(os.path.dirname(__file__), 'core', 'media', file.filename)
async with aiofiles.open(filename, 'wb') as out_file:
content = await file.read() # async read
await out_file.write(content) # async write
return Recognizer.recognize_visionai(json_data, filename)