Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -88,18 +88,19 @@ def create_the_final_results(fabric: Image.Image, person: Image.Image, mask: Ima
|
|
| 88 |
|
| 89 |
return results
|
| 90 |
|
| 91 |
-
def load_image_from_base64(
|
| 92 |
"""Decodes a Base64 string and opens it as a PIL Image."""
|
| 93 |
-
if ","
|
| 94 |
-
|
| 95 |
try:
|
| 96 |
-
img_data = base64.b64decode(
|
| 97 |
img = Image.open(io.BytesIO(img_data))
|
| 98 |
-
return img.convert(
|
| 99 |
except Exception as e:
|
| 100 |
print(f"Error loading image from base64: {e}")
|
| 101 |
return None
|
| 102 |
|
|
|
|
| 103 |
# === API ENDPOINTS (CORRECT AND GUARANTEED) ===
|
| 104 |
|
| 105 |
@app.get("/")
|
|
@@ -123,6 +124,7 @@ async def api_generate(request: Request, inputs: ApiInput):
|
|
| 123 |
# Load person and fabric images from base64
|
| 124 |
person = load_image_from_base64(inputs.person_base64)
|
| 125 |
fabric = load_image_from_base64(inputs.fabric_base64)
|
|
|
|
| 126 |
|
| 127 |
if person is None or fabric is None:
|
| 128 |
raise HTTPException(status_code=400, detail="Could not decode base64 images.")
|
|
|
|
| 88 |
|
| 89 |
return results
|
| 90 |
|
| 91 |
+
def load_image_from_base64(base64_str: str, mode='RGB'):
|
| 92 |
"""Decodes a Base64 string and opens it as a PIL Image."""
|
| 93 |
+
if "," in base64_str:
|
| 94 |
+
base64_str = base64_str.split(",")[1]
|
| 95 |
try:
|
| 96 |
+
img_data = base64.b64decode(base64_str)
|
| 97 |
img = Image.open(io.BytesIO(img_data))
|
| 98 |
+
return img.convert(mode) # Convert to the specified mode (e.g., 'RGB', 'L', etc.)
|
| 99 |
except Exception as e:
|
| 100 |
print(f"Error loading image from base64: {e}")
|
| 101 |
return None
|
| 102 |
|
| 103 |
+
|
| 104 |
# === API ENDPOINTS (CORRECT AND GUARANTEED) ===
|
| 105 |
|
| 106 |
@app.get("/")
|
|
|
|
| 124 |
# Load person and fabric images from base64
|
| 125 |
person = load_image_from_base64(inputs.person_base64)
|
| 126 |
fabric = load_image_from_base64(inputs.fabric_base64)
|
| 127 |
+
mask = load_image_from_base64(inputs.mask_base64, mode='L')
|
| 128 |
|
| 129 |
if person is None or fabric is None:
|
| 130 |
raise HTTPException(status_code=400, detail="Could not decode base64 images.")
|