ahmetyaylalioglu commited on
Commit
ab8972c
·
verified ·
1 Parent(s): 08c4bfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -19,9 +19,9 @@ def mask_to_rgb(mask):
19
  bg_transparent[mask == 1] = [0, 255, 0, 127]
20
  return bg_transparent
21
 
22
- def get_processed_inputs(image, x, y):
23
- input_points = [[[x, y]]]
24
- inputs = processor(image, input_points, return_tensors="pt").to(device)
25
  with torch.no_grad():
26
  outputs = model(**inputs)
27
  masks = processor.image_processor.post_process_masks(
@@ -49,18 +49,17 @@ def inpaint(raw_image, input_mask, prompt, negative_prompt=None, seed=74294536,
49
  ).images[0]
50
  return image
51
 
52
- def gradio_interface(image, x, y, positive_prompt, negative_prompt):
53
  raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
54
- mask = get_processed_inputs(raw_image, x, y)
55
  processed_image = inpaint(raw_image, mask, positive_prompt, negative_prompt)
56
  return processed_image, mask_to_rgb(mask)
57
 
58
  iface = gr.Interface(
59
  fn=gradio_interface,
60
  inputs=[
61
- gr.Image(type="numpy"),
62
- gr.Number(label="X coordinate"),
63
- gr.Number(label="Y coordinate"),
64
  gr.Textbox(label="Positive Prompt", placeholder="Enter positive prompt here"),
65
  gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
66
  ],
@@ -69,7 +68,7 @@ iface = gr.Interface(
69
  gr.Image(label="Segmentation Mask")
70
  ],
71
  title="Interactive Image Inpainting",
72
- description="Enter X and Y coordinates for the point to segment, provide prompts, and see the inpainted result."
73
  )
74
 
75
  iface.launch(share=True)
 
19
  bg_transparent[mask == 1] = [0, 255, 0, 127]
20
  return bg_transparent
21
 
22
+ def get_processed_inputs(image, points):
23
+ input_points = [points]
24
+ inputs = processor(image, input_points=input_points, return_tensors="pt").to(device)
25
  with torch.no_grad():
26
  outputs = model(**inputs)
27
  masks = processor.image_processor.post_process_masks(
 
49
  ).images[0]
50
  return image
51
 
52
+ def gradio_interface(image, points, positive_prompt, negative_prompt):
53
  raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
54
+ mask = get_processed_inputs(raw_image, points)
55
  processed_image = inpaint(raw_image, mask, positive_prompt, negative_prompt)
56
  return processed_image, mask_to_rgb(mask)
57
 
58
  iface = gr.Interface(
59
  fn=gradio_interface,
60
  inputs=[
61
+ gr.Image(type="numpy", label="Input Image"),
62
+ gr.Image(type="numpy", label="Click to select points", tool="sketch", brush_radius=1),
 
63
  gr.Textbox(label="Positive Prompt", placeholder="Enter positive prompt here"),
64
  gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
65
  ],
 
68
  gr.Image(label="Segmentation Mask")
69
  ],
70
  title="Interactive Image Inpainting",
71
+ description="Click on the image to select points for segmentation, provide prompts, and see the inpainted result."
72
  )
73
 
74
  iface.launch(share=True)