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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
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 = [[list(map(int, point.split(',')))] for point in points.split('|') if point]
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
- # Updated Gradio interface
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, "a car driving on Mars. Studio lights, 1970s", "artifacts, low quality, distortion")
57
  return processed_image, mask_to_rgb(mask)
58
 
59
  iface = gr.Interface(
60
  fn=gradio_interface,
61
  inputs=[
62
- gr.Image(image_mode='RGB'), # Removed image_shape parameter
63
- "text" # To allow users to enter points manually or through another input method
 
 
64
  ],
65
- outputs=["image", "image"]
 
 
 
 
 
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)