Update handler.py
Browse files- handler.py +3 -2
handler.py
CHANGED
|
@@ -3,7 +3,7 @@ import torch
|
|
| 3 |
from diffusers import FluxKontextPipeline
|
| 4 |
from io import BytesIO
|
| 5 |
import base64
|
| 6 |
-
from PIL import Image
|
| 7 |
|
| 8 |
class EndpointHandler:
|
| 9 |
def __init__(self, path: str = ""):
|
|
@@ -57,10 +57,11 @@ class EndpointHandler:
|
|
| 57 |
if not image_input:
|
| 58 |
return {"error": "Missing 'image' (base64) in input data."}
|
| 59 |
|
| 60 |
-
# Decode image from base64
|
| 61 |
try:
|
| 62 |
image_bytes = base64.b64decode(image_input)
|
| 63 |
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
|
|
| 64 |
except Exception as e:
|
| 65 |
return {"error": f"Failed to decode 'image' as base64: {str(e)}"}
|
| 66 |
|
|
|
|
| 3 |
from diffusers import FluxKontextPipeline
|
| 4 |
from io import BytesIO
|
| 5 |
import base64
|
| 6 |
+
from PIL import Image, ImageOps # Updated import
|
| 7 |
|
| 8 |
class EndpointHandler:
|
| 9 |
def __init__(self, path: str = ""):
|
|
|
|
| 57 |
if not image_input:
|
| 58 |
return {"error": "Missing 'image' (base64) in input data."}
|
| 59 |
|
| 60 |
+
# Decode image from base64 and correct orientation
|
| 61 |
try:
|
| 62 |
image_bytes = base64.b64decode(image_input)
|
| 63 |
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
| 64 |
+
image = ImageOps.exif_transpose(image) # Correct EXIF orientation here
|
| 65 |
except Exception as e:
|
| 66 |
return {"error": f"Failed to decode 'image' as base64: {str(e)}"}
|
| 67 |
|