Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ def mask_to_rgb(mask):
|
|
20 |
return bg_transparent
|
21 |
|
22 |
def get_processed_inputs(image, points):
|
23 |
-
input_points = [
|
24 |
inputs = processor(image, input_points, return_tensors="pt").to(device)
|
25 |
with torch.no_grad():
|
26 |
outputs = model(**inputs)
|
@@ -49,20 +49,27 @@ def inpaint(raw_image, input_mask, prompt, negative_prompt=None, seed=74294536,
|
|
49 |
).images[0]
|
50 |
return image
|
51 |
|
52 |
-
|
53 |
-
def gradio_interface(image, points):
|
54 |
raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
|
|
|
55 |
mask = get_processed_inputs(raw_image, points)
|
56 |
-
processed_image = inpaint(raw_image, mask,
|
57 |
return processed_image, mask_to_rgb(mask)
|
58 |
|
59 |
iface = gr.Interface(
|
60 |
fn=gradio_interface,
|
61 |
inputs=[
|
62 |
-
gr.Image(
|
63 |
-
"
|
|
|
|
|
64 |
],
|
65 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
66 |
)
|
67 |
|
68 |
iface.launch(share=True)
|
|
|
20 |
return bg_transparent
|
21 |
|
22 |
def get_processed_inputs(image, points):
|
23 |
+
input_points = [points]
|
24 |
inputs = processor(image, input_points, return_tensors="pt").to(device)
|
25 |
with torch.no_grad():
|
26 |
outputs = model(**inputs)
|
|
|
49 |
).images[0]
|
50 |
return image
|
51 |
|
52 |
+
def gradio_interface(image, coordinates, positive_prompt, negative_prompt):
|
|
|
53 |
raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
|
54 |
+
points = [int(coord) for coord in coordinates]
|
55 |
mask = get_processed_inputs(raw_image, points)
|
56 |
+
processed_image = inpaint(raw_image, mask, positive_prompt, negative_prompt)
|
57 |
return processed_image, mask_to_rgb(mask)
|
58 |
|
59 |
iface = gr.Interface(
|
60 |
fn=gradio_interface,
|
61 |
inputs=[
|
62 |
+
gr.Image(type="numpy", tool="select"),
|
63 |
+
gr.Textbox(label="Coordinates (automatically filled)"),
|
64 |
+
gr.Textbox(label="Positive Prompt", placeholder="Enter positive prompt here"),
|
65 |
+
gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
|
66 |
],
|
67 |
+
outputs=[
|
68 |
+
gr.Image(label="Inpainted Image"),
|
69 |
+
gr.Image(label="Segmentation Mask")
|
70 |
+
],
|
71 |
+
title="Interactive Image Inpainting",
|
72 |
+
description="Select an area on the image, provide prompts, and see the inpainted result."
|
73 |
)
|
74 |
|
75 |
iface.launch(share=True)
|