ahmetyaylalioglu commited on
Commit
2e6d89c
·
verified ·
1 Parent(s): c636056

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -20,9 +20,9 @@ def mask_to_rgb(mask):
20
  bg_transparent[mask == 1] = [0, 255, 0, 127] # Green mask with some transparency
21
  return bg_transparent
22
 
23
- def get_processed_inputs(image, points):
24
- """ Process the input image and points using SAM model and processor. """
25
- inputs = processor(image, input_points=points, return_tensors="pt").to(device)
26
  with torch.no_grad():
27
  outputs = model(**inputs)
28
  masks = processor.image_processor.post_process_masks(
@@ -53,11 +53,10 @@ def inpaint(raw_image, input_mask, prompt, negative_prompt=None, seed=74294536,
53
  ).images[0]
54
  return image
55
 
56
- def gradio_interface(image, points_json, positive_prompt, negative_prompt):
57
- """ Gradio interface function to handle image, points for segmentation, and prompts. """
58
- points = [[(point['x'], point['y']) for point in stroke['points']] for stroke in points_json]
59
  raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
60
- mask = get_processed_inputs(raw_image, points)
61
  processed_image = inpaint(raw_image, mask, positive_prompt, negative_prompt)
62
  return processed_image, mask_to_rgb(mask)
63
 
@@ -65,7 +64,7 @@ iface = gr.Interface(
65
  fn=gradio_interface,
66
  inputs=[
67
  gr.Image(type="numpy", label="Input Image"),
68
- gr.Image(type="json", label="Click to select points", tool="sketch", brush_radius=1, shape=(512, 512)),
69
  gr.Textbox(label="Positive Prompt", placeholder="Enter positive prompt here"),
70
  gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
71
  ],
@@ -74,7 +73,7 @@ iface = gr.Interface(
74
  gr.Image(label="Segmentation Mask")
75
  ],
76
  title="Interactive Image Inpainting",
77
- description="Click on the image to select points for segmentation, provide prompts, and see the inpainted result."
78
  )
79
 
80
- iface.launch(share=True)
 
20
  bg_transparent[mask == 1] = [0, 255, 0, 127] # Green mask with some transparency
21
  return bg_transparent
22
 
23
+ def get_processed_inputs(image, drawing):
24
+ """ Process the input image and drawing using SAM model and processor. """
25
+ inputs = processor(image, return_tensors="pt").to(device)
26
  with torch.no_grad():
27
  outputs = model(**inputs)
28
  masks = processor.image_processor.post_process_masks(
 
53
  ).images[0]
54
  return image
55
 
56
+ def gradio_interface(image, drawing, positive_prompt, negative_prompt):
57
+ """ Gradio interface function to handle image, drawing, and prompts. """
 
58
  raw_image = Image.fromarray(image).convert("RGB").resize((512, 512))
59
+ mask = get_processed_inputs(raw_image, drawing)
60
  processed_image = inpaint(raw_image, mask, positive_prompt, negative_prompt)
61
  return processed_image, mask_to_rgb(mask)
62
 
 
64
  fn=gradio_interface,
65
  inputs=[
66
  gr.Image(type="numpy", label="Input Image"),
67
+ gr.Sketch(label="Draw on the image", shape=(512, 512)),
68
  gr.Textbox(label="Positive Prompt", placeholder="Enter positive prompt here"),
69
  gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
70
  ],
 
73
  gr.Image(label="Segmentation Mask")
74
  ],
75
  title="Interactive Image Inpainting",
76
+ description="Draw on the image to select areas for segmentation, provide prompts, and see the inpainted result."
77
  )
78
 
79
+ iface.launch(share=True