Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,12 +12,12 @@ import io
|
|
| 12 |
sam_model = SamModel.from_pretrained("facebook/sam-vit-huge", torch_dtype=torch.float32).to("cpu")
|
| 13 |
sam_processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
|
| 14 |
|
| 15 |
-
# Initialize Inpainting pipeline on CPU
|
| 16 |
inpaint_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 17 |
-
"
|
| 18 |
torch_dtype=torch.float32
|
| 19 |
).to("cpu")
|
| 20 |
-
#
|
| 21 |
|
| 22 |
def mask_to_rgba(mask):
|
| 23 |
"""
|
|
@@ -157,7 +157,13 @@ with gr.Blocks() as demo:
|
|
| 157 |
|
| 158 |
with gr.Row():
|
| 159 |
with gr.Column():
|
| 160 |
-
image_input = gr.Image(label="Upload Image", type="pil",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
prompt_input = gr.Textbox(label="Replacement Prompt", placeholder="e.g., a red sports car", lines=2)
|
| 162 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", placeholder="e.g., blurry, low quality", lines=2)
|
| 163 |
seed_input = gr.Number(label="Seed", value=42)
|
|
@@ -167,17 +173,10 @@ with gr.Blocks() as demo:
|
|
| 167 |
masked_output = gr.Image(label="Selected Object Mask Overlay")
|
| 168 |
augmented_output = gr.Image(label="Augmented Image")
|
| 169 |
|
| 170 |
-
#
|
| 171 |
-
points = gr.State([])
|
| 172 |
-
|
| 173 |
-
def update_points(selected_points):
|
| 174 |
-
return selected_points
|
| 175 |
-
|
| 176 |
-
image_input.select(update_points, inputs=image_input, outputs=points)
|
| 177 |
-
|
| 178 |
process_button.click(
|
| 179 |
fn=process,
|
| 180 |
-
inputs=[image_input,
|
| 181 |
outputs=[masked_output, augmented_output]
|
| 182 |
)
|
| 183 |
|
|
|
|
| 12 |
sam_model = SamModel.from_pretrained("facebook/sam-vit-huge", torch_dtype=torch.float32).to("cpu")
|
| 13 |
sam_processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
|
| 14 |
|
| 15 |
+
# Initialize Inpainting pipeline on CPU with a compatible model
|
| 16 |
inpaint_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
|
| 17 |
+
"stabilityai/stable-diffusion-2-inpainting",
|
| 18 |
torch_dtype=torch.float32
|
| 19 |
).to("cpu")
|
| 20 |
+
# No need for model_cpu_offload on CPU
|
| 21 |
|
| 22 |
def mask_to_rgba(mask):
|
| 23 |
"""
|
|
|
|
| 157 |
|
| 158 |
with gr.Row():
|
| 159 |
with gr.Column():
|
| 160 |
+
image_input = gr.Image(label="Upload Image", type="pil", interactive=True, elem_id="image")
|
| 161 |
+
points_input = gr.Points(
|
| 162 |
+
label="Select Points on the Object",
|
| 163 |
+
show_label=True,
|
| 164 |
+
source="image", # Links Points to the Image component via elem_id
|
| 165 |
+
interactive=True
|
| 166 |
+
)
|
| 167 |
prompt_input = gr.Textbox(label="Replacement Prompt", placeholder="e.g., a red sports car", lines=2)
|
| 168 |
negative_prompt_input = gr.Textbox(label="Negative Prompt", placeholder="e.g., blurry, low quality", lines=2)
|
| 169 |
seed_input = gr.Number(label="Seed", value=42)
|
|
|
|
| 173 |
masked_output = gr.Image(label="Selected Object Mask Overlay")
|
| 174 |
augmented_output = gr.Image(label="Augmented Image")
|
| 175 |
|
| 176 |
+
# Bind the process function to the button click
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
process_button.click(
|
| 178 |
fn=process,
|
| 179 |
+
inputs=[image_input, points_input, prompt_input, negative_prompt_input, seed_input, guidance_scale_input],
|
| 180 |
outputs=[masked_output, augmented_output]
|
| 181 |
)
|
| 182 |
|