Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- .gitignore +12 -0
- README.md +65 -6
- app.py +168 -0
- requirements.txt +7 -0
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
*$py.class
|
| 4 |
+
*.so
|
| 5 |
+
.Python
|
| 6 |
+
env/
|
| 7 |
+
venv/
|
| 8 |
+
.venv/
|
| 9 |
+
*.egg-info/
|
| 10 |
+
.DS_Store
|
| 11 |
+
.ipynb_checkpoints/
|
| 12 |
+
flagged/
|
README.md
CHANGED
|
@@ -1,12 +1,71 @@
|
|
| 1 |
---
|
| 2 |
-
title: RMBG
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: RMBG-3.0 Background Removal & Image Editing
|
| 3 |
+
emoji: 🎨
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: cc-by-nc-4.0
|
| 11 |
+
models:
|
| 12 |
+
- briaai/RMBG-3.0
|
| 13 |
+
tags:
|
| 14 |
+
- image-editing
|
| 15 |
+
- background-removal
|
| 16 |
+
- image-to-image
|
| 17 |
+
- diffusion
|
| 18 |
+
short_description: Background removal and image editing with RMBG-3.0
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# RMBG-3.0 - Background Removal & Image Editing
|
| 22 |
+
|
| 23 |
+
This Space demonstrates **RMBG-3.0**, an advanced image editing model built on [Fibo-Edit](https://huggingface.co/briaai/Fibo-Edit) by Bria AI.
|
| 24 |
+
|
| 25 |
+
## 🎯 Capabilities
|
| 26 |
+
|
| 27 |
+
- **Background Removal**: Remove backgrounds with high precision
|
| 28 |
+
- **Object Removal**: Remove specific objects from images
|
| 29 |
+
- **Style Transfer**: Apply different artistic styles
|
| 30 |
+
- **Recoloring**: Change colors of objects
|
| 31 |
+
- **Relighting**: Adjust lighting conditions
|
| 32 |
+
- **Masked Editing**: Target specific regions with masks
|
| 33 |
+
|
| 34 |
+
## 🚀 How to Use
|
| 35 |
+
|
| 36 |
+
1. **Upload an Image**: Click on the input image area to upload your photo
|
| 37 |
+
2. **Add a Mask (Optional)**: Upload a mask to edit specific regions only
|
| 38 |
+
3. **Provide Instructions**: Describe what you want to change (e.g., "remove the background")
|
| 39 |
+
4. **Adjust Settings**: Optionally tune the number of steps and guidance scale
|
| 40 |
+
5. **Process**: Click the "Process Image" button
|
| 41 |
+
|
| 42 |
+
## 📖 Example Instructions
|
| 43 |
+
|
| 44 |
+
- `remove the background`
|
| 45 |
+
- `make it look vintage`
|
| 46 |
+
- `change the car color to red`
|
| 47 |
+
- `remove the person`
|
| 48 |
+
- `add dramatic sunset lighting`
|
| 49 |
+
- `change to winter scene`
|
| 50 |
+
|
| 51 |
+
## 🏗️ Model Details
|
| 52 |
+
|
| 53 |
+
- **Model**: [briaai/RMBG-3.0](https://huggingface.co/briaai/RMBG-3.0)
|
| 54 |
+
- **Base**: FIBO-Edit architecture (8B parameters)
|
| 55 |
+
- **Training**: Exclusively on licensed, copyright-safe data
|
| 56 |
+
- **License**: [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) (Non-commercial use only)
|
| 57 |
+
|
| 58 |
+
## 💼 Commercial Use
|
| 59 |
+
|
| 60 |
+
For commercial licensing, please contact [Bria AI](https://bria.ai/contact-us).
|
| 61 |
+
|
| 62 |
+
## 🔗 Links
|
| 63 |
+
|
| 64 |
+
- [Model Card](https://huggingface.co/briaai/RMBG-3.0)
|
| 65 |
+
- [Fibo-Edit Base Model](https://huggingface.co/briaai/Fibo-Edit)
|
| 66 |
+
- [Bria AI](https://bria.ai)
|
| 67 |
+
- [GitHub](https://github.com/Bria-AI/)
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
Built with ❤️ by [Bria AI](https://bria.ai)
|
app.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import BriaFiboEditPipeline
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load the model
|
| 8 |
+
print("Loading RMBG-3.0 model...")
|
| 9 |
+
pipe = BriaFiboEditPipeline.from_pretrained(
|
| 10 |
+
"briaai/RMBG-3.0",
|
| 11 |
+
torch_dtype=torch.bfloat16,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Check if CUDA is available
|
| 15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
+
pipe.to(device)
|
| 17 |
+
print(f"Model loaded on {device}")
|
| 18 |
+
|
| 19 |
+
def process_image(image, mask, instruction, num_steps, guidance_scale):
|
| 20 |
+
"""
|
| 21 |
+
Process an image with RMBG-3.0
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
image: Input image (PIL Image)
|
| 25 |
+
mask: Optional mask image (PIL Image)
|
| 26 |
+
instruction: Text instruction for editing
|
| 27 |
+
num_steps: Number of inference steps
|
| 28 |
+
guidance_scale: Guidance scale for generation
|
| 29 |
+
"""
|
| 30 |
+
if image is None:
|
| 31 |
+
return None, "Please upload an image"
|
| 32 |
+
|
| 33 |
+
if not instruction or instruction.strip() == "":
|
| 34 |
+
return None, "Please provide an editing instruction"
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
# Prepare inputs
|
| 38 |
+
kwargs = {
|
| 39 |
+
"image": image,
|
| 40 |
+
"prompt": instruction,
|
| 41 |
+
"num_inference_steps": num_steps,
|
| 42 |
+
"guidance_scale": guidance_scale
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# Add mask if provided
|
| 46 |
+
if mask is not None:
|
| 47 |
+
kwargs["mask"] = mask.convert("L")
|
| 48 |
+
|
| 49 |
+
# Run the pipeline
|
| 50 |
+
result = pipe(**kwargs).images[0]
|
| 51 |
+
|
| 52 |
+
return result, "✅ Image processed successfully!"
|
| 53 |
+
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return None, f"❌ Error: {str(e)}"
|
| 56 |
+
|
| 57 |
+
# Create Gradio interface
|
| 58 |
+
with gr.Blocks(title="RMBG-3.0 - Background Removal & Image Editing") as demo:
|
| 59 |
+
gr.Markdown("""
|
| 60 |
+
# RMBG-3.0 - Background Removal & Image Editing
|
| 61 |
+
|
| 62 |
+
Powered by [Bria AI's RMBG-3.0 model](https://huggingface.co/briaai/RMBG-3.0)
|
| 63 |
+
|
| 64 |
+
This model performs advanced image editing including:
|
| 65 |
+
- **Background removal**: "remove the background"
|
| 66 |
+
- **Object removal**: "remove the person", "remove the car"
|
| 67 |
+
- **Style changes**: "make it look vintage", "change to winter scene"
|
| 68 |
+
- **Recoloring**: "change the car color to red"
|
| 69 |
+
- **Relighting**: "add dramatic lighting"
|
| 70 |
+
|
| 71 |
+
### How to use:
|
| 72 |
+
1. Upload your image
|
| 73 |
+
2. (Optional) Upload a mask to edit specific regions
|
| 74 |
+
3. Describe what you want to change
|
| 75 |
+
4. Adjust settings and click Process!
|
| 76 |
+
""")
|
| 77 |
+
|
| 78 |
+
with gr.Row():
|
| 79 |
+
with gr.Column(scale=1):
|
| 80 |
+
input_image = gr.Image(
|
| 81 |
+
label="Input Image",
|
| 82 |
+
type="pil",
|
| 83 |
+
height=400
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
mask_image = gr.Image(
|
| 87 |
+
label="Mask (Optional - for targeted edits)",
|
| 88 |
+
type="pil",
|
| 89 |
+
height=200
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
instruction = gr.Textbox(
|
| 93 |
+
label="Editing Instruction",
|
| 94 |
+
placeholder="E.g., 'remove the background', 'change car color to blue', 'make it look vintage'",
|
| 95 |
+
lines=3
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 99 |
+
num_steps = gr.Slider(
|
| 100 |
+
minimum=20,
|
| 101 |
+
maximum=100,
|
| 102 |
+
value=50,
|
| 103 |
+
step=1,
|
| 104 |
+
label="Number of Steps"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
guidance_scale = gr.Slider(
|
| 108 |
+
minimum=1.0,
|
| 109 |
+
maximum=15.0,
|
| 110 |
+
value=5.0,
|
| 111 |
+
step=0.5,
|
| 112 |
+
label="Guidance Scale"
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
process_btn = gr.Button("🚀 Process Image", variant="primary")
|
| 116 |
+
|
| 117 |
+
with gr.Column(scale=1):
|
| 118 |
+
output_image = gr.Image(
|
| 119 |
+
label="Output Image",
|
| 120 |
+
type="pil",
|
| 121 |
+
height=400
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
status_text = gr.Textbox(
|
| 125 |
+
label="Status",
|
| 126 |
+
interactive=False,
|
| 127 |
+
lines=2
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
# Examples
|
| 131 |
+
gr.Markdown("### Examples")
|
| 132 |
+
gr.Examples(
|
| 133 |
+
examples=[
|
| 134 |
+
["Remove the background"],
|
| 135 |
+
["Make it look vintage"],
|
| 136 |
+
["Change the lighting to dramatic sunset"],
|
| 137 |
+
["Remove the person"],
|
| 138 |
+
["Change the car color to red"],
|
| 139 |
+
],
|
| 140 |
+
inputs=instruction,
|
| 141 |
+
label="Example Instructions"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
# Connect the button
|
| 145 |
+
process_btn.click(
|
| 146 |
+
fn=process_image,
|
| 147 |
+
inputs=[input_image, mask_image, instruction, num_steps, guidance_scale],
|
| 148 |
+
outputs=[output_image, status_text]
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
gr.Markdown("""
|
| 152 |
+
---
|
| 153 |
+
### About RMBG-3.0
|
| 154 |
+
|
| 155 |
+
RMBG-3.0 is built on [Fibo-Edit](https://huggingface.co/briaai/Fibo-Edit), an 8B parameter image editing model
|
| 156 |
+
that uses structured prompts for precise, deterministic editing.
|
| 157 |
+
|
| 158 |
+
- **Model**: [briaai/RMBG-3.0](https://huggingface.co/briaai/RMBG-3.0)
|
| 159 |
+
- **Architecture**: Based on FIBO with 8B parameters
|
| 160 |
+
- **Training**: Exclusively on licensed data
|
| 161 |
+
- **License**: Non-commercial use ([CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/))
|
| 162 |
+
|
| 163 |
+
For commercial use, please [contact Bria AI](https://bria.ai/contact-us).
|
| 164 |
+
""")
|
| 165 |
+
|
| 166 |
+
# Launch the app
|
| 167 |
+
if __name__ == "__main__":
|
| 168 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0.0
|
| 2 |
+
diffusers>=0.30.0
|
| 3 |
+
transformers>=4.40.0
|
| 4 |
+
accelerate>=0.30.0
|
| 5 |
+
safetensors>=0.4.0
|
| 6 |
+
pillow>=10.0.0
|
| 7 |
+
gradio>=4.0.0
|