OriLib commited on
Commit
4ef44ad
·
verified ·
1 Parent(s): a5f4f9e

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -30,15 +30,24 @@ def process_image(image, instruction, num_steps=50, guidance_scale=5.0):
30
  return None, "Please provide an editing instruction"
31
 
32
  try:
33
- # Run the pipeline
34
- result = pipe(
35
  image=image,
36
  prompt=instruction,
37
  num_inference_steps=num_steps,
38
  guidance_scale=guidance_scale
39
  ).images[0]
40
 
41
- return result, "✅ Image processed successfully!"
 
 
 
 
 
 
 
 
 
42
 
43
  except Exception as e:
44
  return None, f"❌ Error: {str(e)}"
@@ -75,9 +84,9 @@ with gr.Blocks(title="RMBG-3.0 - Background Removal & Image Editing") as demo:
75
 
76
  with gr.Accordion("Advanced Settings", open=False):
77
  num_steps = gr.Slider(
78
- minimum=4,
79
- maximum=100,
80
- value=50,
81
  step=1,
82
  label="Number of Steps"
83
  )
 
30
  return None, "Please provide an editing instruction"
31
 
32
  try:
33
+ # Run the pipeline to get the grayscale alpha matte
34
+ mask = pipe(
35
  image=image,
36
  prompt=instruction,
37
  num_inference_steps=num_steps,
38
  guidance_scale=guidance_scale
39
  ).images[0]
40
 
41
+ # Convert original image to RGBA
42
+ original_rgba = image.convert("RGBA")
43
+
44
+ # Convert mask to grayscale (in case it's not already)
45
+ mask_gray = mask.convert("L")
46
+
47
+ # Use the mask as the alpha channel
48
+ original_rgba.putalpha(mask_gray)
49
+
50
+ return original_rgba, "✅ Image processed successfully!"
51
 
52
  except Exception as e:
53
  return None, f"❌ Error: {str(e)}"
 
84
 
85
  with gr.Accordion("Advanced Settings", open=False):
86
  num_steps = gr.Slider(
87
+ minimum=1,
88
+ maximum=50,
89
+ value=4,
90
  step=1,
91
  label="Number of Steps"
92
  )