-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
87 lines (71 loc) ยท 2.65 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from fastapi import FastAPI, File, UploadFile, Form
from api.anime import face2paint
from api.restore import microsoft_restore, restoreimg,cloudinary_upload
from api.removebg import Background_Removal
from api.generate import limewire,Item
from api.outpaint import segmindOutpaint
from api.upscale import limewire_upscale, photai_upscale
from api.inpaint import segmindInpaint
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from mangum import Mangum
app = FastAPI()
origins = [
"http://localhost.tiangolo.com",
"https://localhost.tiangolo.com",
"http://localhost:3000",
"http://localhost:8080",
"http://localhost:5173",
"https://imaginari-one.vercel.app",
"https://imaginari-frontend.vercel.app"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
handler = Mangum(app, lifespan="off")
# @app.get("/test")
# def test():
# return {"message": "Hello World"}
@app.post("/generate")
def generate(item: Item):
response = limewire(item.style, item.prompt, item.negative_prompt)
return {"output": response['url']}
@app.post("/upscale")
def upscale(image: UploadFile = File(...)):
file = cloudinary_upload(image)
response = photai_upscale(file['url'],file['name'])
# response = limewire_upscale(image)
return {"output": response}
@app.post("/inpainting")
def inpainting(image: UploadFile = File(...),mask: UploadFile = File(...),prompt: str = Form(...),negative_prompt: str = Form(None)):
image = cloudinary_upload(image)
mask = cloudinary_upload(mask)
response = segmindInpaint(image['url'],mask['url'],prompt,negative_prompt)
return {"output": response}
@app.post("/outpainting")
def outpainting(image: UploadFile = File(...),prompt: str = Form(...),negative_prompt: str = Form(None)):
file = cloudinary_upload(image)
response = segmindOutpaint(file['url'], prompt, negative_prompt)
return {"output": response}
@app.post("/removebg")
def removebg(image: UploadFile = File(...)):
file = cloudinary_upload(image)
response = Background_Removal(file['url'])
return {"output": response}
@app.post("/restore")
def restore(image: UploadFile = File(...)):
imgfile = cloudinary_upload(image)
# response = restoreimg(imgfile['url'],imgfile['name'])
response = microsoft_restore(imgfile['url'])
# return {"output": response['data']['2k']['url']}
return {"output": response}
@app.post("/toanime")
def toanime(image: UploadFile = File(...)):
response_url = face2paint(image)
return {"output": response_url['body']['imageUrl']}
if __name__ == "__main__":
uvicorn.run(app)