Update handler.py
Browse files- handler.py +4 -6
handler.py
CHANGED
|
@@ -2,10 +2,9 @@ import torch
|
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetModel
|
| 4 |
from diffusers.pipelines import FluxControlNetPipeline
|
| 5 |
-
from
|
| 6 |
-
import io
|
| 7 |
|
| 8 |
-
class
|
| 9 |
def __init__(self, model_dir="huyai123/Flux.1-dev-Image-Upscaler"):
|
| 10 |
# Load model and pipeline
|
| 11 |
self.controlnet = FluxControlNetModel.from_pretrained(
|
|
@@ -30,7 +29,7 @@ class CustomHandler:
|
|
| 30 |
|
| 31 |
def postprocess(self, output):
|
| 32 |
# Save output image to a file-like object
|
| 33 |
-
buffer =
|
| 34 |
output.save(buffer, format="PNG")
|
| 35 |
buffer.seek(0) # Reset buffer pointer
|
| 36 |
return buffer
|
|
@@ -44,9 +43,8 @@ class CustomHandler:
|
|
| 44 |
control_image=control_image,
|
| 45 |
controlnet_conditioning_scale=0.6,
|
| 46 |
num_inference_steps=28,
|
| 47 |
-
guidance_scale=3.5,
|
| 48 |
height=control_image.size[1],
|
| 49 |
width=control_image.size[0],
|
| 50 |
).images[0]
|
| 51 |
# Postprocess output
|
| 52 |
-
return self.postprocess(output_image)
|
|
|
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetModel
|
| 4 |
from diffusers.pipelines import FluxControlNetPipeline
|
| 5 |
+
from io import BytesIO
|
|
|
|
| 6 |
|
| 7 |
+
class EndpointHandler:
|
| 8 |
def __init__(self, model_dir="huyai123/Flux.1-dev-Image-Upscaler"):
|
| 9 |
# Load model and pipeline
|
| 10 |
self.controlnet = FluxControlNetModel.from_pretrained(
|
|
|
|
| 29 |
|
| 30 |
def postprocess(self, output):
|
| 31 |
# Save output image to a file-like object
|
| 32 |
+
buffer = BytesIO()
|
| 33 |
output.save(buffer, format="PNG")
|
| 34 |
buffer.seek(0) # Reset buffer pointer
|
| 35 |
return buffer
|
|
|
|
| 43 |
control_image=control_image,
|
| 44 |
controlnet_conditioning_scale=0.6,
|
| 45 |
num_inference_steps=28,
|
|
|
|
| 46 |
height=control_image.size[1],
|
| 47 |
width=control_image.size[0],
|
| 48 |
).images[0]
|
| 49 |
# Postprocess output
|
| 50 |
+
return self.postprocess(output_image)
|