Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -45,22 +45,26 @@ def transform_image(face_image):
|
|
45 |
# Resize the face image
|
46 |
processed_face_image = processed_face_image.resize(desired_size, Image.LANCZOS)
|
47 |
|
48 |
-
#
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# Perform the transformation using the configured pipeline
|
53 |
image = pipeline(
|
54 |
prompt="soyjak",
|
55 |
-
ip_adapter_image=[
|
56 |
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
57 |
num_inference_steps=30,
|
58 |
generator=generator,
|
59 |
).images[0]
|
60 |
|
61 |
-
# Move the pipeline back to CPU after processing
|
62 |
pipeline.to("cpu")
|
63 |
-
return image
|
64 |
|
65 |
# Gradio interface setup
|
66 |
demo = gr.Interface(
|
|
|
45 |
# Resize the face image
|
46 |
processed_face_image = processed_face_image.resize(desired_size, Image.LANCZOS)
|
47 |
|
48 |
+
# Convert PIL images to PyTorch tensors
|
49 |
+
processed_face_tensor = transforms.ToTensor()(processed_face_image).unsqueeze(0).to("cuda")
|
50 |
+
style_image_tensor = transforms.ToTensor()(style_image).unsqueeze(0).to("cuda")
|
51 |
+
|
52 |
+
# Ensure tensors are the correct shape (C, H, W)
|
53 |
+
if processed_face_tensor.shape[1:] != (3, 1280, 1280):
|
54 |
+
raise ValueError(f"Face image tensor shape is {processed_face_tensor.shape}, but expected shape is (3, 1280, 1280)")
|
55 |
|
56 |
# Perform the transformation using the configured pipeline
|
57 |
image = pipeline(
|
58 |
prompt="soyjak",
|
59 |
+
ip_adapter_image=[style_image_tensor, processed_face_tensor],
|
60 |
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
61 |
num_inference_steps=30,
|
62 |
generator=generator,
|
63 |
).images[0]
|
64 |
|
65 |
+
# Move the pipeline back to CPU after processing to release GPU resources
|
66 |
pipeline.to("cpu")
|
67 |
+
return transforms.ToPILImage()(image.squeeze(0))
|
68 |
|
69 |
# Gradio interface setup
|
70 |
demo = gr.Interface(
|