assaomri commited on
Commit
a348d63
·
verified ·
1 Parent(s): 3dcb0d1

Sync from Bria-AI/huggingface-demos @ 5f2630e

Browse files
Files changed (2) hide show
  1. app.py +167 -35
  2. bria_logo.png +0 -0
app.py CHANGED
@@ -1,9 +1,12 @@
 
 
 
 
1
  import spaces
2
  import gradio as gr
3
  import torch
4
  from diffusers import BriaFiboEditPipeline
5
  from PIL import Image
6
- import tempfile
7
 
8
  # Load the model on CPU at module level (ZeroGPU moves to CUDA inside @spaces.GPU)
9
  print("Loading Fibo-Edit-RMBG model...")
@@ -13,7 +16,7 @@ pipe = BriaFiboEditPipeline.from_pretrained(
13
  )
14
  print("Model loaded on CPU")
15
 
16
- INSTRUCTION = {'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.'}
17
 
18
 
19
  @spaces.GPU(duration=300)
@@ -43,66 +46,195 @@ def process(image, num_steps=10, guidance_scale=1.0):
43
  return (image.convert("RGBA"), result), tmp.name
44
 
45
 
46
- with gr.Blocks(title="Fibo-Edit-RMBG - Background Removal") as demo:
47
- gr.Markdown("""
48
- # Fibo-Edit-RMBG - Background Removal
49
-
50
- Powered by <a href="https://huggingface.co/briaai/Fibo-Edit-RMBG" target="_blank">Bria AI's Fibo-Edit-RMBG model</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- This model performs background removal on any image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- ### How to use:
55
- 1. Upload your image
56
- 2. Adjust settings if needed (optional)
57
- 3. Click Process!
 
 
 
58
  """)
59
 
60
- with gr.Row():
61
  with gr.Column(scale=1):
62
- input_image = gr.Image(label="Input Image", type="pil", height=400)
63
 
64
- with gr.Accordion("Advanced Settings", open=False):
65
  num_steps = gr.Slider(
66
  minimum=1,
67
  maximum=50,
68
  value=10,
69
  step=1,
70
- label="Number of Steps",
71
  )
72
  guidance_scale = gr.Slider(
73
  minimum=1.0,
74
  maximum=15.0,
75
  value=1.0,
76
  step=0.5,
77
- label="Guidance Scale",
78
  )
79
 
80
- process_btn = gr.Button("Remove Background", variant="primary", size="lg")
81
 
82
  with gr.Column(scale=1):
83
  slider = gr.ImageSlider(
84
- label="Original vs Background Removed",
85
  type="pil",
86
  image_mode="RGBA",
87
  format="png",
88
  slider_position=50,
89
- max_height=500,
90
  container=True,
91
  )
92
- download_file = gr.File(label="Download Result (PNG with transparency)")
93
-
94
- gr.Markdown("""
95
- ---
96
- ### About Fibo-Edit-RMBG
97
-
98
- Fibo-Edit-RMBG is built on <a href="https://huggingface.co/briaai/Fibo-Edit" target="_blank">Fibo-Edit</a>, an 8B parameter image editing model
99
- that uses structured prompts for precise, deterministic editing.
100
-
101
- - **Model**: <a href="https://huggingface.co/briaai/Fibo-Edit-RMBG" target="_blank">briaai/Fibo-Edit-RMBG</a>
102
- - **Architecture**: Based on FIBO with 8B parameters
103
- - **License**: Non-commercial use (<a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a>)
104
-
105
- For commercial use, please <a href="https://bria.ai/contact-us" target="_blank">contact Bria AI</a>.
106
  """)
107
 
108
  process_btn.click(
@@ -112,4 +244,4 @@ For commercial use, please <a href="https://bria.ai/contact-us" target="_blank">
112
  )
113
 
114
  if __name__ == "__main__":
115
- demo.launch(show_error=True, theme=gr.themes.Soft(primary_hue="sky"))
 
1
+ import os
2
+ import base64
3
+ import tempfile
4
+
5
  import spaces
6
  import gradio as gr
7
  import torch
8
  from diffusers import BriaFiboEditPipeline
9
  from PIL import Image
 
10
 
11
  # Load the model on CPU at module level (ZeroGPU moves to CUDA inside @spaces.GPU)
12
  print("Loading Fibo-Edit-RMBG model...")
 
16
  )
17
  print("Model loaded on CPU")
18
 
19
+ INSTRUCTION = {'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.'}
20
 
21
 
22
  @spaces.GPU(duration=300)
 
46
  return (image.convert("RGBA"), result), tmp.name
47
 
48
 
49
+ def _load_logo():
50
+ """Embed the bundled logo as a data URI so the header never depends on an external CDN."""
51
+ try:
52
+ with open(os.path.join(os.path.dirname(__file__), "bria_logo.png"), "rb") as f:
53
+ return "data:image/png;base64," + base64.b64encode(f.read()).decode("utf-8")
54
+ except Exception:
55
+ return "https://cdn.sanity.io/images/zppcnj0l/production/d0f4aef10abdcc4bacaebeade789ea8c3e453882-210x132.png"
56
+
57
+
58
+ BRIA_LOGO = _load_logo()
59
+
60
+
61
+ # ------------------------------------------------------------------ #
62
+ # Theme + styling — Bria brand (purple #5300C9, magenta accent) #
63
+ # ------------------------------------------------------------------ #
64
+ bria_theme = gr.themes.Soft(
65
+ primary_hue=gr.themes.Color(
66
+ c50="#f3ebff", c100="#e4d3ff", c200="#c9a6ff", c300="#a86bff",
67
+ c400="#8a3dff", c500="#5300C9", c600="#4700ab", c700="#37008a",
68
+ c800="#28006b", c900="#1c0050", c950="#120038",
69
+ ),
70
+ secondary_hue=gr.themes.Color(
71
+ c50="#ffe9f4", c100="#ffd0e6", c200="#ffa1cd", c300="#ff6fb2",
72
+ c400="#f5399a", c500="#e2138a", c600="#c00b74", c700="#99095c",
73
+ c800="#730745", c900="#520531", c950="#340120",
74
+ ),
75
+ neutral_hue="slate",
76
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
77
+ radius_size=gr.themes.sizes.radius_lg,
78
+ ).set(
79
+ body_background_fill="#f6f5fb",
80
+ body_background_fill_dark="#0f0b1a",
81
+ block_background_fill="white",
82
+ block_background_fill_dark="#1a1330",
83
+ block_border_width="1px",
84
+ block_shadow="0 1px 3px rgba(28,0,80,0.06), 0 8px 24px rgba(28,0,80,0.05)",
85
+ button_primary_background_fill="linear-gradient(90deg, #5300C9 0%, #8a3dff 100%)",
86
+ button_primary_background_fill_hover="linear-gradient(90deg, #4700ab 0%, #7a2dff 100%)",
87
+ button_primary_text_color="white",
88
+ button_large_radius="12px",
89
+ )
90
 
91
+ css = """
92
+ .gradio-container { max-width: 1180px !important; margin: 0 auto !important; }
93
+
94
+ /* ---- Header ---- */
95
+ #bria-header {
96
+ display: flex;
97
+ align-items: center;
98
+ gap: 18px;
99
+ padding: 22px 26px;
100
+ margin-bottom: 8px;
101
+ background: linear-gradient(120deg, #ffffff 0%, #f3ecff 100%);
102
+ border: 1px solid rgba(83, 0, 201, 0.12);
103
+ border-radius: 18px;
104
+ }
105
+ .dark #bria-header {
106
+ background: linear-gradient(120deg, #1a1330 0%, #241640 100%);
107
+ border-color: rgba(138, 61, 255, 0.25);
108
+ }
109
+ #bria-header img { height: 52px; width: auto; }
110
+ #bria-header .title-block h1 {
111
+ margin: 0;
112
+ font-size: 1.7rem;
113
+ font-weight: 800;
114
+ letter-spacing: -0.02em;
115
+ color: #1c0050;
116
+ }
117
+ .dark #bria-header .title-block h1 { color: #f0eafc; }
118
+ #bria-header .title-block p {
119
+ margin: 4px 0 0 0;
120
+ font-size: 0.95rem;
121
+ color: #6b6580;
122
+ }
123
+ .dark #bria-header .title-block p { color: #b3abc9; }
124
+ #bria-header .pill {
125
+ display: inline-block;
126
+ margin-top: 8px;
127
+ padding: 3px 12px;
128
+ font-size: 0.72rem;
129
+ font-weight: 700;
130
+ letter-spacing: 0.04em;
131
+ text-transform: uppercase;
132
+ color: #5300C9;
133
+ background: rgba(83, 0, 201, 0.09);
134
+ border-radius: 999px;
135
+ }
136
+ .dark #bria-header .pill { color: #c9a6ff; background: rgba(138, 61, 255, 0.15); }
137
+
138
+ /* ---- Steps helper ---- */
139
+ #steps { font-size: 0.92rem; color: #4b4661; margin: 2px 4px 10px; }
140
+ .dark #steps { color: #b3abc9; }
141
+ #steps b { color: #5300C9; }
142
+ .dark #steps b { color: #c9a6ff; }
143
+
144
+ /* ---- Image panels ---- */
145
+ #image_upload, #output-img { border-radius: 14px; min-height: 360px; }
146
+ #image_upload img, #output-img img { object-fit: contain; }
147
+
148
+ /* ---- Run button ---- */
149
+ #run_button {
150
+ width: 100%;
151
+ height: 54px;
152
+ font-size: 1.05rem;
153
+ font-weight: 700;
154
+ box-shadow: 0 6px 18px rgba(83, 0, 201, 0.28);
155
+ }
156
+ #run_button:hover { box-shadow: 0 8px 22px rgba(83, 0, 201, 0.38); }
157
+
158
+ /* ---- Footer ---- */
159
+ #bria-footer {
160
+ margin-top: 28px;
161
+ padding-top: 18px;
162
+ border-top: 1px solid rgba(83, 0, 201, 0.12);
163
+ text-align: center;
164
+ font-size: 0.88rem;
165
+ color: #6b6580;
166
+ line-height: 1.7;
167
+ }
168
+ #bria-footer a { color: #5300C9; text-decoration: none; font-weight: 600; }
169
+ #bria-footer a:hover { text-decoration: underline; }
170
+ .dark #bria-footer { color: #b3abc9; border-color: rgba(138, 61, 255, 0.22); }
171
+ .dark #bria-footer a { color: #c9a6ff; }
172
+ """
173
+
174
+ with gr.Blocks(theme=bria_theme, css=css, title="BRIA Fibo-Edit-RMBG") as demo:
175
+ gr.HTML(f"""
176
+ <div id="bria-header">
177
+ <img src="{BRIA_LOGO}" alt="BRIA logo" />
178
+ <div class="title-block">
179
+ <h1>Remove Background</h1>
180
+ <p>Fibo-Edit-RMBG — background removal via Bria's 8B FIBO-Edit model, on licensed data.</p>
181
+ <span class="pill">Open model · Fibo-Edit-RMBG</span>
182
+ </div>
183
+ </div>
184
+ """)
185
 
186
+ gr.HTML("""
187
+ <div id="steps">
188
+ <b>1.</b> Upload an image &nbsp;·&nbsp;
189
+ <b>2.</b> (optional) tune the settings &nbsp;·&nbsp;
190
+ <b>3.</b> Hit <b>Remove Background</b> &nbsp;·&nbsp;
191
+ <b>4.</b> Drag the slider to compare, then download the PNG
192
+ </div>
193
  """)
194
 
195
+ with gr.Row(equal_height=False):
196
  with gr.Column(scale=1):
197
+ input_image = gr.Image(label="Input image", type="pil", elem_id="image_upload")
198
 
199
+ with gr.Accordion("Advanced settings", open=False):
200
  num_steps = gr.Slider(
201
  minimum=1,
202
  maximum=50,
203
  value=10,
204
  step=1,
205
+ label="Number of steps",
206
  )
207
  guidance_scale = gr.Slider(
208
  minimum=1.0,
209
  maximum=15.0,
210
  value=1.0,
211
  step=0.5,
212
+ label="Guidance scale",
213
  )
214
 
215
+ process_btn = gr.Button("✨ Remove Background", variant="primary", elem_id="run_button")
216
 
217
  with gr.Column(scale=1):
218
  slider = gr.ImageSlider(
219
+ label="Original vs. background removed",
220
  type="pil",
221
  image_mode="RGBA",
222
  format="png",
223
  slider_position=50,
224
+ elem_id="output-img",
225
  container=True,
226
  )
227
+ download_file = gr.File(label="PNG with transparent background")
228
+
229
+ gr.HTML("""
230
+ <div id="bria-footer">
231
+ <p>
232
+ Fibo-Edit-RMBG is built on the 8B <a href="https://huggingface.co/briaai/Fibo-Edit" target="_blank">FIBO-Edit</a> model and is open for non-commercial use (<a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a>).<br/>
233
+ <a href="https://huggingface.co/briaai/Fibo-Edit-RMBG" target="_blank">Model card</a> ·
234
+ <a href="https://bria.ai/contact-us" target="_blank">Commercial licensing</a> ·
235
+ <a href="https://bria.ai" target="_blank">Bria AI</a>
236
+ </p>
237
+ </div>
 
 
 
238
  """)
239
 
240
  process_btn.click(
 
244
  )
245
 
246
  if __name__ == "__main__":
247
+ demo.launch(show_error=True)
bria_logo.png ADDED