Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,29 +43,30 @@ def transform_image(face_image):
|
|
| 43 |
else:
|
| 44 |
raise ValueError("Unsupported image format")
|
| 45 |
|
| 46 |
-
# Resize the face image
|
| 47 |
processed_face_image = processed_face_image.resize(desired_size, Image.LANCZOS)
|
| 48 |
-
|
| 49 |
-
# Convert PIL images to PyTorch tensors
|
| 50 |
processed_face_tensor = transforms.ToTensor()(processed_face_image).unsqueeze(0).to("cuda")
|
| 51 |
-
style_image_tensor = transforms.ToTensor()(style_image).unsqueeze(0).to("cuda")
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
# Perform the transformation using the configured pipeline
|
| 58 |
image = pipeline(
|
| 59 |
prompt="soyjak",
|
| 60 |
-
ip_adapter_image=[style_image_tensor, processed_face_tensor],
|
| 61 |
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
| 62 |
num_inference_steps=30,
|
| 63 |
generator=generator,
|
| 64 |
).images[0]
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
# Move the pipeline back to CPU after processing to release GPU resources
|
| 67 |
pipeline.to("cpu")
|
| 68 |
-
return
|
| 69 |
|
| 70 |
# Gradio interface setup
|
| 71 |
demo = gr.Interface(
|
|
|
|
| 43 |
else:
|
| 44 |
raise ValueError("Unsupported image format")
|
| 45 |
|
| 46 |
+
# Resize the face image and convert to tensor
|
| 47 |
processed_face_image = processed_face_image.resize(desired_size, Image.LANCZOS)
|
|
|
|
|
|
|
| 48 |
processed_face_tensor = transforms.ToTensor()(processed_face_image).unsqueeze(0).to("cuda")
|
|
|
|
| 49 |
|
| 50 |
+
# Load the style image from the local path, resize it and convert to tensor
|
| 51 |
+
style_image_path = "examples/soyjak2.jpeg" # Ensure this path is correct
|
| 52 |
+
style_image = Image.open(style_image_path).resize(desired_size, Image.LANCZOS)
|
| 53 |
+
style_image_tensor = transforms.ToTensor()(style_image).unsqueeze(0).to("cuda")
|
| 54 |
|
| 55 |
# Perform the transformation using the configured pipeline
|
| 56 |
image = pipeline(
|
| 57 |
prompt="soyjak",
|
| 58 |
+
ip_adapter_image=[style_image_tensor, processed_face_tensor], # Ensure these are tensors
|
| 59 |
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
| 60 |
num_inference_steps=30,
|
| 61 |
generator=generator,
|
| 62 |
).images[0]
|
| 63 |
|
| 64 |
+
# Convert the tensor to a PIL Image to display it in Gradio
|
| 65 |
+
image = transforms.ToPILImage()(image.squeeze(0))
|
| 66 |
+
|
| 67 |
# Move the pipeline back to CPU after processing to release GPU resources
|
| 68 |
pipeline.to("cpu")
|
| 69 |
+
return image
|
| 70 |
|
| 71 |
# Gradio interface setup
|
| 72 |
demo = gr.Interface(
|