muhammadsalmanalfaridzi commited on
Commit
7e07d39
β€’
1 Parent(s): a2649a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -22,12 +22,6 @@ def load_stable_diffusion_model():
22
  # Initialize the model globally
23
  sd_model = load_stable_diffusion_model()
24
 
25
- def remove_background_stable_diffusion(image_path):
26
- image = Image.open(image_path).convert("RGB")
27
- prompt = "Remove background from the image"
28
- output = sd_model(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
29
- return output
30
-
31
  def remove_background_rembg(input_path):
32
  print(f"Removing background using rembg for image: {input_path}")
33
  with open(input_path, 'rb') as i:
@@ -437,9 +431,7 @@ def process_single_image(image_path, output_folder, bg_method, canvas_size_name,
437
  filename = os.path.basename(image_path)
438
  try:
439
  print(f"Processing image: {filename}")
440
- if bg_method == 'stable_diffusion':
441
- image_with_no_bg = remove_background_stable_diffusion(image_path)
442
- elif bg_method == 'rembg':
443
  image_with_no_bg = remove_background_rembg(image_path) # Placeholder for existing function
444
  elif bg_method == 'bria':
445
  image_with_no_bg = remove_background_bria(image_path) # Placeholder for existing function
@@ -471,8 +463,8 @@ def process_single_image(image_path, output_folder, bg_method, canvas_size_name,
471
  output_filename = f"{os.path.splitext(filename)[0]}.{output_ext}"
472
  output_path = os.path.join(output_folder, output_filename)
473
 
474
- # Apply watermark only if the filename ends with "_01" and watermark_path is provided
475
- if os.path.splitext(filename)[0].endswith("_01") and watermark_path:
476
  watermark = Image.open(watermark_path).convert("RGBA")
477
  canvas.paste(watermark, (0, 0), watermark)
478
  log.append({"action": "add_watermark"})
@@ -689,7 +681,7 @@ with gr.Blocks(theme="NoCrypt/miku@1.2.2") as iface:
689
  num_workers = gr.Slider(minimum=1, maximum=16, step=1, label="Number of Workers", value=5)
690
 
691
  with gr.Row():
692
- bg_method = gr.Radio(choices=["bria", "rembg", "stable_diffusion"], label="Background Removal Method", value="stable_diffusion")
693
  bg_choice = gr.Radio(choices=["transparent", "white", "custom"], label="Background Choice", value="white")
694
  custom_color = gr.ColorPicker(label="Custom Background Color", value="#ffffff", visible=False)
695
 
 
22
  # Initialize the model globally
23
  sd_model = load_stable_diffusion_model()
24
 
 
 
 
 
 
 
25
  def remove_background_rembg(input_path):
26
  print(f"Removing background using rembg for image: {input_path}")
27
  with open(input_path, 'rb') as i:
 
431
  filename = os.path.basename(image_path)
432
  try:
433
  print(f"Processing image: {filename}")
434
+ if bg_method == 'rembg':
 
 
435
  image_with_no_bg = remove_background_rembg(image_path) # Placeholder for existing function
436
  elif bg_method == 'bria':
437
  image_with_no_bg = remove_background_bria(image_path) # Placeholder for existing function
 
463
  output_filename = f"{os.path.splitext(filename)[0]}.{output_ext}"
464
  output_path = os.path.join(output_folder, output_filename)
465
 
466
+ # Apply watermark if watermark_path is provided
467
+ if watermark_path:
468
  watermark = Image.open(watermark_path).convert("RGBA")
469
  canvas.paste(watermark, (0, 0), watermark)
470
  log.append({"action": "add_watermark"})
 
681
  num_workers = gr.Slider(minimum=1, maximum=16, step=1, label="Number of Workers", value=5)
682
 
683
  with gr.Row():
684
+ bg_method = gr.Radio(choices=["bria", "rembg"], label="Background Removal Method", value="rembg")
685
  bg_choice = gr.Radio(choices=["transparent", "white", "custom"], label="Background Choice", value="white")
686
  custom_color = gr.ColorPicker(label="Custom Background Color", value="#ffffff", visible=False)
687