Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 17 |
pipe.to(device)
|
| 18 |
print(f"Model loaded on {device}")
|
| 19 |
|
| 20 |
-
def process_image(image,
|
| 21 |
"""
|
| 22 |
Process an image with RMBG-3.0
|
| 23 |
"""
|
|
@@ -28,20 +28,13 @@ def process_image(image, mask, instruction, num_steps=50, guidance_scale=5.0):
|
|
| 28 |
return None, "Please provide an editing instruction"
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
# Prepare inputs
|
| 32 |
-
kwargs = {
|
| 33 |
-
"image": image,
|
| 34 |
-
"prompt": instruction,
|
| 35 |
-
"num_inference_steps": num_steps,
|
| 36 |
-
"guidance_scale": guidance_scale
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
# Add mask if provided
|
| 40 |
-
if mask is not None:
|
| 41 |
-
kwargs["mask"] = mask.convert("L")
|
| 42 |
-
|
| 43 |
# Run the pipeline
|
| 44 |
-
result = pipe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
return result, "✅ Image processed successfully!"
|
| 47 |
|
|
@@ -64,9 +57,9 @@ with gr.Blocks(title="RMBG-3.0 - Background Removal & Image Editing") as demo:
|
|
| 64 |
|
| 65 |
### How to use:
|
| 66 |
1. Upload your image
|
| 67 |
-
2.
|
| 68 |
-
3.
|
| 69 |
-
4.
|
| 70 |
""")
|
| 71 |
|
| 72 |
with gr.Row():
|
|
@@ -77,12 +70,6 @@ with gr.Blocks(title="RMBG-3.0 - Background Removal & Image Editing") as demo:
|
|
| 77 |
height=400
|
| 78 |
)
|
| 79 |
|
| 80 |
-
mask_image = gr.Image(
|
| 81 |
-
label="Mask (Optional - for targeted edits)",
|
| 82 |
-
type="pil",
|
| 83 |
-
height=200
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
instruction = gr.Textbox(
|
| 87 |
label="Editing Instruction",
|
| 88 |
value="{'edit_instruction':'Generate a detailed grayscale alpha matte. Map the opaque foreground to white and the background to black. Produce soft, anti-aliased grayscale gradients at the edges of the subject to represent fine details and transparency.'}",
|
|
@@ -138,7 +125,7 @@ with gr.Blocks(title="RMBG-3.0 - Background Removal & Image Editing") as demo:
|
|
| 138 |
# Connect the button
|
| 139 |
process_btn.click(
|
| 140 |
fn=process_image,
|
| 141 |
-
inputs=[input_image,
|
| 142 |
outputs=[output_image, status_text]
|
| 143 |
)
|
| 144 |
|
|
|
|
| 17 |
pipe.to(device)
|
| 18 |
print(f"Model loaded on {device}")
|
| 19 |
|
| 20 |
+
def process_image(image, instruction, num_steps=50, guidance_scale=5.0):
|
| 21 |
"""
|
| 22 |
Process an image with RMBG-3.0
|
| 23 |
"""
|
|
|
|
| 28 |
return None, "Please provide an editing instruction"
|
| 29 |
|
| 30 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Run the pipeline
|
| 32 |
+
result = pipe(
|
| 33 |
+
image=image,
|
| 34 |
+
prompt=instruction,
|
| 35 |
+
num_inference_steps=num_steps,
|
| 36 |
+
guidance_scale=guidance_scale
|
| 37 |
+
).images[0]
|
| 38 |
|
| 39 |
return result, "✅ Image processed successfully!"
|
| 40 |
|
|
|
|
| 57 |
|
| 58 |
### How to use:
|
| 59 |
1. Upload your image
|
| 60 |
+
2. Review or modify the editing instruction
|
| 61 |
+
3. Adjust settings if needed
|
| 62 |
+
4. Click Process!
|
| 63 |
""")
|
| 64 |
|
| 65 |
with gr.Row():
|
|
|
|
| 70 |
height=400
|
| 71 |
)
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
instruction = gr.Textbox(
|
| 74 |
label="Editing Instruction",
|
| 75 |
value="{'edit_instruction':'Generate a detailed grayscale alpha matte. Map the opaque foreground to white and the background to black. Produce soft, anti-aliased grayscale gradients at the edges of the subject to represent fine details and transparency.'}",
|
|
|
|
| 125 |
# Connect the button
|
| 126 |
process_btn.click(
|
| 127 |
fn=process_image,
|
| 128 |
+
inputs=[input_image, instruction, num_steps, guidance_scale],
|
| 129 |
outputs=[output_image, status_text]
|
| 130 |
)
|
| 131 |
|