Update app.py
Browse files
app.py
CHANGED
|
@@ -54,12 +54,16 @@ gfpgan = GFPGANer(
|
|
| 54 |
device=DEVICE
|
| 55 |
)
|
| 56 |
|
|
|
|
| 57 |
# Stable Diffusion Img2Img
|
|
|
|
|
|
|
| 58 |
sd_pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 59 |
"runwayml/stable-diffusion-v1-5",
|
| 60 |
-
torch_dtype=
|
| 61 |
).to(DEVICE)
|
| 62 |
|
|
|
|
| 63 |
# ===== Endpoints =====
|
| 64 |
|
| 65 |
@app.post("/remove-bg")
|
|
@@ -77,7 +81,7 @@ async def remove_bg(file: UploadFile = File(...)):
|
|
| 77 |
@app.post("/enhance")
|
| 78 |
async def enhance(file: UploadFile = File(...)):
|
| 79 |
img = Image.open(file.file).convert("RGB")
|
| 80 |
-
out,_ = upscaler.
|
| 81 |
|
| 82 |
fname = f"{uuid.uuid4().hex}.png"
|
| 83 |
out.save(os.path.join(OUTPUT_DIR, fname))
|
|
@@ -88,7 +92,7 @@ async def enhance(file: UploadFile = File(...)):
|
|
| 88 |
async def upscale(file: UploadFile = File(...), scale: int = Form(2)):
|
| 89 |
img = Image.open(file.file).convert("RGB")
|
| 90 |
upscaler.scale = scale
|
| 91 |
-
out = upscaler.
|
| 92 |
|
| 93 |
fname = f"{uuid.uuid4().hex}.png"
|
| 94 |
out.save(os.path.join(OUTPUT_DIR, fname))
|
|
|
|
| 54 |
device=DEVICE
|
| 55 |
)
|
| 56 |
|
| 57 |
+
|
| 58 |
# Stable Diffusion Img2Img
|
| 59 |
+
dtype = torch.float16 if DEVICE == "cuda" else torch.float32
|
| 60 |
+
|
| 61 |
sd_pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 62 |
"runwayml/stable-diffusion-v1-5",
|
| 63 |
+
torch_dtype=dtype
|
| 64 |
).to(DEVICE)
|
| 65 |
|
| 66 |
+
|
| 67 |
# ===== Endpoints =====
|
| 68 |
|
| 69 |
@app.post("/remove-bg")
|
|
|
|
| 81 |
@app.post("/enhance")
|
| 82 |
async def enhance(file: UploadFile = File(...)):
|
| 83 |
img = Image.open(file.file).convert("RGB")
|
| 84 |
+
out, _ = upscaler.enhance(img)
|
| 85 |
|
| 86 |
fname = f"{uuid.uuid4().hex}.png"
|
| 87 |
out.save(os.path.join(OUTPUT_DIR, fname))
|
|
|
|
| 92 |
async def upscale(file: UploadFile = File(...), scale: int = Form(2)):
|
| 93 |
img = Image.open(file.file).convert("RGB")
|
| 94 |
upscaler.scale = scale
|
| 95 |
+
out, _ = upscaler.enhance(img, outscale=scale)
|
| 96 |
|
| 97 |
fname = f"{uuid.uuid4().hex}.png"
|
| 98 |
out.save(os.path.join(OUTPUT_DIR, fname))
|