vvaibhav commited on
Commit
d633b07
·
verified ·
1 Parent(s): 452ea00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -12,12 +12,12 @@ import io
12
  sam_model = SamModel.from_pretrained("facebook/sam-vit-huge", torch_dtype=torch.float32).to("cpu")
13
  sam_processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
14
 
15
- # Initialize Inpainting pipeline on CPU
16
  inpaint_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
17
- "runwayml/stable-diffusion-inpainting",
18
  torch_dtype=torch.float32
19
  ).to("cpu")
20
- # Removed model_cpu_offload as it's unnecessary for CPU
21
 
22
  def mask_to_rgba(mask):
23
  """
@@ -157,7 +157,13 @@ with gr.Blocks() as demo:
157
 
158
  with gr.Row():
159
  with gr.Column():
160
- image_input = gr.Image(label="Upload Image", type="pil", tool="point", interactive=True)
 
 
 
 
 
 
161
  prompt_input = gr.Textbox(label="Replacement Prompt", placeholder="e.g., a red sports car", lines=2)
162
  negative_prompt_input = gr.Textbox(label="Negative Prompt", placeholder="e.g., blurry, low quality", lines=2)
163
  seed_input = gr.Number(label="Seed", value=42)
@@ -167,17 +173,10 @@ with gr.Blocks() as demo:
167
  masked_output = gr.Image(label="Selected Object Mask Overlay")
168
  augmented_output = gr.Image(label="Augmented Image")
169
 
170
- # Capture points selected on the image
171
- points = gr.State([])
172
-
173
- def update_points(selected_points):
174
- return selected_points
175
-
176
- image_input.select(update_points, inputs=image_input, outputs=points)
177
-
178
  process_button.click(
179
  fn=process,
180
- inputs=[image_input, points, prompt_input, negative_prompt_input, seed_input, guidance_scale_input],
181
  outputs=[masked_output, augmented_output]
182
  )
183
 
 
12
  sam_model = SamModel.from_pretrained("facebook/sam-vit-huge", torch_dtype=torch.float32).to("cpu")
13
  sam_processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
14
 
15
+ # Initialize Inpainting pipeline on CPU with a compatible model
16
  inpaint_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
17
+ "stabilityai/stable-diffusion-2-inpainting",
18
  torch_dtype=torch.float32
19
  ).to("cpu")
20
+ # No need for model_cpu_offload on CPU
21
 
22
  def mask_to_rgba(mask):
23
  """
 
157
 
158
  with gr.Row():
159
  with gr.Column():
160
+ image_input = gr.Image(label="Upload Image", type="pil", interactive=True, elem_id="image")
161
+ points_input = gr.Points(
162
+ label="Select Points on the Object",
163
+ show_label=True,
164
+ source="image", # Links Points to the Image component via elem_id
165
+ interactive=True
166
+ )
167
  prompt_input = gr.Textbox(label="Replacement Prompt", placeholder="e.g., a red sports car", lines=2)
168
  negative_prompt_input = gr.Textbox(label="Negative Prompt", placeholder="e.g., blurry, low quality", lines=2)
169
  seed_input = gr.Number(label="Seed", value=42)
 
173
  masked_output = gr.Image(label="Selected Object Mask Overlay")
174
  augmented_output = gr.Image(label="Augmented Image")
175
 
176
+ # Bind the process function to the button click
 
 
 
 
 
 
 
177
  process_button.click(
178
  fn=process,
179
+ inputs=[image_input, points_input, prompt_input, negative_prompt_input, seed_input, guidance_scale_input],
180
  outputs=[masked_output, augmented_output]
181
  )
182