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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -19,8 +19,8 @@ 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, 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,18 +49,18 @@ def inpaint(raw_image, input_mask, prompt, negative_prompt=None, seed=74294536,
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
  ],
@@ -69,7 +69,7 @@ iface = gr.Interface(
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)
 
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)
 
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
  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)