-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (36 loc) · 1002 Bytes
/
main.py
File metadata and controls
50 lines (36 loc) · 1002 Bytes
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
46
47
48
49
50
from typing import List
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
from starlette.responses import Response
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["GET", "PUT"],
allow_headers=["*"],
)
class Annotation(BaseModel):
x: int
y: int
label: str
class Image(BaseModel):
url: str
annotations: List[Annotation] = []
database = [
Image(url=f"https://picsum.photos/id/{i}/800/600")
for i in range(20)
]
@app.get("/images")
async def images():
return [{"id": f"{i}", "url": image.url} for i, image in enumerate(database)]
@app.get("/annotation/{id}")
async def annotations(id: str):
image = database[int(id)]
return image.annotations
@app.put("/annotation/{id}")
async def annotations(id: str, body: List[Annotation]):
image = database[int(id)]
image.annotations = body
return Response()