-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (34 loc) · 1.01 KB
/
main.py
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
40
41
42
43
44
45
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from api import azure
from pydantic import BaseModel
app = FastAPI(debug=True)
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/describe")
async def describe(image: UploadFile = File(...)):
temp_file = image.file
return azure.describe_image(temp_file.read())
@app.post("/read")
async def read(image: UploadFile = File(...)):
temp_file = image.file
return azure.read_image(temp_file.read())
@app.post("/command")
async def command(audio: UploadFile = File(...)):
temp_file = audio.file
ends_with_m4a = audio.filename.endswith(".m4a")
return azure.get_command(temp_file, ends_with_m4a)