Update handler.py
Browse files- handler.py +9 -1
handler.py
CHANGED
|
@@ -3,7 +3,8 @@ import torch
|
|
| 3 |
from diffusers import FluxKontextPipeline
|
| 4 |
from io import BytesIO
|
| 5 |
import base64
|
| 6 |
-
from PIL import Image, ImageOps
|
|
|
|
| 7 |
|
| 8 |
class EndpointHandler:
|
| 9 |
def __init__(self, path: str = ""):
|
|
@@ -78,6 +79,13 @@ class EndpointHandler:
|
|
| 78 |
guidance_scale=2.0
|
| 79 |
).images[0]
|
| 80 |
print("🎨 Image generated.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
except Exception as e:
|
| 82 |
return {"error": f"Model inference failed: {str(e)}"}
|
| 83 |
|
|
|
|
| 3 |
from diffusers import FluxKontextPipeline
|
| 4 |
from io import BytesIO
|
| 5 |
import base64
|
| 6 |
+
from PIL import Image, ImageOps
|
| 7 |
+
import numpy as np # Added import
|
| 8 |
|
| 9 |
class EndpointHandler:
|
| 10 |
def __init__(self, path: str = ""):
|
|
|
|
| 79 |
guidance_scale=2.0
|
| 80 |
).images[0]
|
| 81 |
print("🎨 Image generated.")
|
| 82 |
+
|
| 83 |
+
# 💡 HARD CLAMP pixel values to [0, 255] to prevent NaN/black outputs
|
| 84 |
+
output_array = np.array(output)
|
| 85 |
+
output_array = np.clip(output_array, 0, 255).astype(np.uint8)
|
| 86 |
+
output = Image.fromarray(output_array)
|
| 87 |
+
print("🛑 Hard clamped output pixel values to [0, 255].")
|
| 88 |
+
|
| 89 |
except Exception as e:
|
| 90 |
return {"error": f"Model inference failed: {str(e)}"}
|
| 91 |
|