Spaces:
Sleeping
Sleeping
Add main space file
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ try:
|
|
| 18 |
except Exception as e:
|
| 19 |
raise RuntimeError(f"Error loading segmentation model: {e}")
|
| 20 |
|
|
|
|
| 21 |
# Load Inpainting Model (Without CUDA)
|
| 22 |
try:
|
| 23 |
pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting")
|
|
@@ -28,9 +29,7 @@ except Exception as e:
|
|
| 28 |
def load_and_preprocess_image(image_path):
|
| 29 |
image = load_rgb(image_path)
|
| 30 |
padded_image, pads = pad(image, factor=32, border=cv2.BORDER_CONSTANT)
|
| 31 |
-
|
| 32 |
-
x = transform(image=padded_image)["image"]
|
| 33 |
-
x = torch.unsqueeze(tensor_from_rgb_image(x), 0)
|
| 34 |
return x, image, pads
|
| 35 |
|
| 36 |
def segment_cloth(image_tensor, model, pads):
|
|
@@ -65,6 +64,7 @@ def image_segmentation_and_inpainting(image, prompt="Chinese Red and Golder Armo
|
|
| 65 |
|
| 66 |
output_image = perform_inpainting(temp_image_path, mask_path, prompt)
|
| 67 |
output_image = resize_and_upscale(output_image, 1280, 720) # You can adjust the size
|
|
|
|
| 68 |
return output_image
|
| 69 |
except Exception as e:
|
| 70 |
raise gr.Error(f"Error processing image: {e}")
|
|
@@ -81,4 +81,4 @@ with gr.Blocks() as demo:
|
|
| 81 |
|
| 82 |
run_button.click(fn=image_segmentation_and_inpainting, inputs=[image_input, prompt_input], outputs=image_output)
|
| 83 |
|
| 84 |
-
demo.launch(share=True)
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
raise RuntimeError(f"Error loading segmentation model: {e}")
|
| 20 |
|
| 21 |
+
|
| 22 |
# Load Inpainting Model (Without CUDA)
|
| 23 |
try:
|
| 24 |
pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting")
|
|
|
|
| 29 |
def load_and_preprocess_image(image_path):
|
| 30 |
image = load_rgb(image_path)
|
| 31 |
padded_image, pads = pad(image, factor=32, border=cv2.BORDER_CONSTANT)
|
| 32 |
+
x = torch.unsqueeze(tensor_from_rgb_image(image), 0) # Use original image, not padded
|
|
|
|
|
|
|
| 33 |
return x, image, pads
|
| 34 |
|
| 35 |
def segment_cloth(image_tensor, model, pads):
|
|
|
|
| 64 |
|
| 65 |
output_image = perform_inpainting(temp_image_path, mask_path, prompt)
|
| 66 |
output_image = resize_and_upscale(output_image, 1280, 720) # You can adjust the size
|
| 67 |
+
|
| 68 |
return output_image
|
| 69 |
except Exception as e:
|
| 70 |
raise gr.Error(f"Error processing image: {e}")
|
|
|
|
| 81 |
|
| 82 |
run_button.click(fn=image_segmentation_and_inpainting, inputs=[image_input, prompt_input], outputs=image_output)
|
| 83 |
|
| 84 |
+
demo.launch(share=True)
|