hpc-yekin
commited on
Commit
·
8a6f0b6
1
Parent(s):
698817b
upgrade to gradio latest & examples added
Browse files- README.md +1 -1
- app.py +16 -16
- gradio_examples/images/1.jpg +0 -0
- gradio_examples/images/2.jpg +0 -0
- gradio_examples/images/3.jpg +0 -0
- gradio_examples/masks/1.png +0 -0
- gradio_examples/masks/2.png +0 -0
- gradio_examples/masks/3.png +0 -0
README.md
CHANGED
|
@@ -5,7 +5,7 @@ colorFrom: green
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
python_version: 3.10.13
|
| 8 |
-
sdk_version: 4.
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
|
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
python_version: 3.10.13
|
| 8 |
+
sdk_version: 4.36.1
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
app.py
CHANGED
|
@@ -18,7 +18,7 @@ args = parser.parse_args()
|
|
| 18 |
# Load configuration and models
|
| 19 |
config = OmegaConf.load(args.config)
|
| 20 |
sd_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 21 |
-
"runwayml/stable-diffusion-inpainting",
|
| 22 |
)
|
| 23 |
clipaway = CLIPAway(
|
| 24 |
sd_pipe=sd_pipeline,
|
|
@@ -59,37 +59,37 @@ def remove_obj(image, uploaded_mask, seed):
|
|
| 59 |
|
| 60 |
# Define example data
|
| 61 |
examples = [
|
| 62 |
-
["
|
| 63 |
-
["
|
| 64 |
-
["
|
| 65 |
-
["
|
| 66 |
]
|
| 67 |
|
| 68 |
-
# Define the Gradio interface
|
| 69 |
with gr.Blocks() as demo:
|
| 70 |
gr.Markdown("<h1 style='text-align:center'>CLIPAway: Harmonizing Focused Embeddings for Removing Objects via Diffusion Models</h1>")
|
| 71 |
gr.Markdown("""
|
| 72 |
<div style='display:flex; justify-content:center; align-items:center;'>
|
| 73 |
-
<a href='https://arxiv.org/abs/2406.09368' style="margin:10px;">Paper</a> |
|
| 74 |
-
<a href='https://yigitekin.github.io/CLIPAway/' style="margin:10px;">Project Website</a> |
|
| 75 |
-
<a href='https://github.com/YigitEkin/CLIPAway' style="margin:10px;">GitHub</a>
|
| 76 |
</div>
|
| 77 |
""")
|
| 78 |
gr.Markdown("""
|
| 79 |
This application allows you to remove objects from images using the CLIPAway method with diffusion models.
|
| 80 |
To use this tool:
|
| 81 |
1. Upload an image.
|
| 82 |
-
2.
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 86 |
Note: The mask should be a binary image where the object to be removed is white and the background is black.
|
| 87 |
""")
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
with gr.Column():
|
| 91 |
-
image_input = gr.Image(label="Upload Image and Sketch Mask", type="pil",
|
| 92 |
-
uploaded_mask = gr.Image(label="Upload Mask
|
| 93 |
seed_input = gr.Number(value=42, label="Seed")
|
| 94 |
process_button = gr.Button("Remove Object")
|
| 95 |
with gr.Column():
|
|
@@ -107,7 +107,7 @@ with gr.Blocks() as demo:
|
|
| 107 |
outputs=result_image
|
| 108 |
)
|
| 109 |
|
| 110 |
-
# Launch the interface
|
| 111 |
if args.share:
|
| 112 |
demo.launch(share=True)
|
| 113 |
else:
|
|
|
|
| 18 |
# Load configuration and models
|
| 19 |
config = OmegaConf.load(args.config)
|
| 20 |
sd_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 21 |
+
"runwayml/stable-diffusion-inpainting", torch_dtype=torch.float32
|
| 22 |
)
|
| 23 |
clipaway = CLIPAway(
|
| 24 |
sd_pipe=sd_pipeline,
|
|
|
|
| 59 |
|
| 60 |
# Define example data
|
| 61 |
examples = [
|
| 62 |
+
["gradio_examples/images/1.jpg", "gradio_examples/masks/1.png", 42],
|
| 63 |
+
["gradio_examples/images/2.jpg", "gradio_examples/masks/2.png", 42],
|
| 64 |
+
["gradio_examples/images/3.jpg", "gradio_examples/masks/3.png", 464],
|
| 65 |
+
["gradio_examples/images/4.jpg", "gradio_examples/masks/4.png", 2024],
|
| 66 |
]
|
| 67 |
|
|
|
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
gr.Markdown("<h1 style='text-align:center'>CLIPAway: Harmonizing Focused Embeddings for Removing Objects via Diffusion Models</h1>")
|
| 70 |
gr.Markdown("""
|
| 71 |
<div style='display:flex; justify-content:center; align-items:center;'>
|
| 72 |
+
<a href='https://arxiv.org/abs/2406.09368' style="margin-right:10px; color:white;">Paper</a> |
|
| 73 |
+
<a href='https://yigitekin.github.io/CLIPAway/' style="margin:10px; color:white;">Project Website</a> |
|
| 74 |
+
<a href='https://github.com/YigitEkin/CLIPAway' style="margin-left:10px; color:white;">GitHub</a>
|
| 75 |
</div>
|
| 76 |
""")
|
| 77 |
gr.Markdown("""
|
| 78 |
This application allows you to remove objects from images using the CLIPAway method with diffusion models.
|
| 79 |
To use this tool:
|
| 80 |
1. Upload an image.
|
| 81 |
+
2. Upload a pre-defined mask if you have one. (If you don't have a mask, and want to sketch one,
|
| 82 |
+
we have provided a gradio demo in our github repository. <br/> Unfortunately, we cannot provide it here due to the compatibility issues with zerogpu.)
|
| 83 |
+
3. Set the seed for reproducibility (default is 42).
|
| 84 |
+
4. Click 'Remove Object' to process the image.
|
| 85 |
+
5. The result will be displayed on the right side.
|
| 86 |
Note: The mask should be a binary image where the object to be removed is white and the background is black.
|
| 87 |
""")
|
| 88 |
|
| 89 |
with gr.Row():
|
| 90 |
with gr.Column():
|
| 91 |
+
image_input = gr.Image(label="Upload Image and Sketch Mask", type="pil", image_mode="RGB")
|
| 92 |
+
uploaded_mask = gr.Image(label="Upload Mask", type="pil", image_mode="L")
|
| 93 |
seed_input = gr.Number(value=42, label="Seed")
|
| 94 |
process_button = gr.Button("Remove Object")
|
| 95 |
with gr.Column():
|
|
|
|
| 107 |
outputs=result_image
|
| 108 |
)
|
| 109 |
|
| 110 |
+
# Launch the interface without caching
|
| 111 |
if args.share:
|
| 112 |
demo.launch(share=True)
|
| 113 |
else:
|
gradio_examples/images/1.jpg
ADDED
|
gradio_examples/images/2.jpg
ADDED
|
gradio_examples/images/3.jpg
ADDED
|
gradio_examples/masks/1.png
ADDED
|
gradio_examples/masks/2.png
ADDED
|
gradio_examples/masks/3.png
ADDED
|