-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
56 lines (45 loc) · 1.42 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
from fastapi import FastAPI
from config import *
from items import EditItem, GenerateItem, ResponseItem
from pipelines import pipe_edit, pipe_generate
from utils import upload_images, get_image
from PIL import Image
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = [
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/v1/generate", response_model=ResponseItem)
async def generate(item: GenerateItem):
return {"images": [
"20230127220712340.jpg",
"20230127220712341.jpg",
"20230127220712342.jpg",
"20230127220712343.jpg",
"20230127220712344.jpg",
"20230127220712345.jpg",
]}
@app.post("/v1/edit", response_model=ResponseItem)
async def edit(item: EditItem):
return {"images": [
"20230127220712340.jpg"
]}
@app.post("/v2/generate", response_model=ResponseItem)
async def generatev2(item: GenerateItem):
images = pipe_generate(item.get_prompt())
filenames = upload_images(images)
return {"images": filenames}
@app.post("/v2/edit", response_model=ResponseItem)
async def editv2(item: EditItem):
source_image = get_image(item.image)
images = pipe_edit(source_image, item.source.get_prompt(),
item.target.get_prompt())
filenames = upload_images(images)
return {"images": filenames}