Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -201,37 +201,84 @@ css = """
|
|
| 201 |
#col-container {
|
| 202 |
margin: 0 auto;
|
| 203 |
max-width: 1024px;
|
|
|
|
| 204 |
}
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
text-align: center;
|
|
|
|
| 207 |
}
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
}
|
| 211 |
-
#edit_text{margin-top: -62px !important}
|
| 212 |
"""
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
with gr.Blocks(css=css) as demo:
|
| 215 |
with gr.Column(elem_id="col-container"):
|
| 216 |
-
gr.HTML(""
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
</div>
|
| 222 |
-
""")
|
| 223 |
with gr.Row():
|
| 224 |
with gr.Column():
|
| 225 |
input_images = gr.Gallery(
|
| 226 |
label="Input Images",
|
| 227 |
-
show_label=
|
| 228 |
-
type="pil",
|
| 229 |
interactive=True
|
| 230 |
)
|
| 231 |
with gr.Column():
|
| 232 |
result = gr.Gallery(
|
| 233 |
label="Result",
|
| 234 |
-
show_label=
|
| 235 |
type="pil"
|
| 236 |
)
|
| 237 |
use_output_btn = gr.Button(
|
|
@@ -242,7 +289,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 242 |
)
|
| 243 |
|
| 244 |
run_button = gr.Button(
|
| 245 |
-
"
|
| 246 |
variant="primary"
|
| 247 |
)
|
| 248 |
|
|
@@ -275,18 +322,18 @@ with gr.Blocks(css=css) as demo:
|
|
| 275 |
minimum=256,
|
| 276 |
maximum=2048,
|
| 277 |
step=8,
|
| 278 |
-
value=
|
| 279 |
)
|
| 280 |
width = gr.Slider(
|
| 281 |
label="Width",
|
| 282 |
minimum=256,
|
| 283 |
maximum=2048,
|
| 284 |
step=8,
|
| 285 |
-
value=
|
| 286 |
)
|
| 287 |
rewrite_prompt = gr.Checkbox(label="Rewrite prompt", value=True)
|
| 288 |
|
| 289 |
-
#
|
| 290 |
DEFAULT_EDIT_PROMPT = "remove acne, marks, black spots, blemishes"
|
| 291 |
|
| 292 |
gr.on(
|
|
@@ -321,6 +368,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 321 |
outputs=[input_images]
|
| 322 |
)
|
| 323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
if __name__ == "__main__":
|
| 326 |
demo.launch()
|
|
|
|
| 201 |
#col-container {
|
| 202 |
margin: 0 auto;
|
| 203 |
max-width: 1024px;
|
| 204 |
+
padding: 20px;
|
| 205 |
}
|
| 206 |
+
|
| 207 |
+
.heading-title {
|
| 208 |
+
text-align: center;
|
| 209 |
+
font-style: italic;
|
| 210 |
+
color: #5b47d1;
|
| 211 |
+
margin: 0;
|
| 212 |
+
padding: 20px 0 12px 0;
|
| 213 |
+
font-size: 1.3em;
|
| 214 |
+
line-height: 1.4;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.image-preview-container {
|
| 218 |
+
width: 100%;
|
| 219 |
+
max-width: 100%;
|
| 220 |
+
overflow: auto;
|
| 221 |
+
background: #222;
|
| 222 |
text-align: center;
|
| 223 |
+
padding: 12px 0;
|
| 224 |
}
|
| 225 |
+
|
| 226 |
+
.image-true-size {
|
| 227 |
+
display: block;
|
| 228 |
+
max-width: none;
|
| 229 |
+
max-height: none;
|
| 230 |
+
width: auto;
|
| 231 |
+
height: auto;
|
| 232 |
+
object-fit: none;
|
| 233 |
+
background: #111;
|
| 234 |
+
border: 1px solid #444;
|
| 235 |
+
margin: 0 auto;
|
| 236 |
}
|
|
|
|
| 237 |
"""
|
| 238 |
|
| 239 |
+
from PIL import Image
|
| 240 |
+
import gradio as gr
|
| 241 |
+
|
| 242 |
+
def get_img_html(img):
|
| 243 |
+
if isinstance(img, list): # If multiple images, use the first
|
| 244 |
+
img = img[0]
|
| 245 |
+
if img is None:
|
| 246 |
+
return '<div>No image loaded.</div>'
|
| 247 |
+
width, height = img.size
|
| 248 |
+
import base64
|
| 249 |
+
from io import BytesIO
|
| 250 |
+
buffer = BytesIO()
|
| 251 |
+
img.save(buffer, format="PNG")
|
| 252 |
+
img_b64 = base64.b64encode(buffer.getvalue()).decode()
|
| 253 |
+
html = f"""
|
| 254 |
+
<div class="image-preview-container">
|
| 255 |
+
<img src="data:image/png;base64,{img_b64}" class="image-true-size"/>
|
| 256 |
+
<div style="color:#ccc;font-size:0.9em;margin-top:6px;">
|
| 257 |
+
Original size: {width} × {height} px
|
| 258 |
+
</div>
|
| 259 |
+
</div>
|
| 260 |
+
"""
|
| 261 |
+
return html
|
| 262 |
+
|
| 263 |
with gr.Blocks(css=css) as demo:
|
| 264 |
with gr.Column(elem_id="col-container"):
|
| 265 |
+
gr.HTML('<div class="heading-title">Upload face image and get your acne, marks, black spots, blemishes removed.</div>')
|
| 266 |
+
|
| 267 |
+
# True-size preview (above gallery)
|
| 268 |
+
preview_html = gr.HTML(value=get_img_html(None))
|
| 269 |
+
|
|
|
|
|
|
|
| 270 |
with gr.Row():
|
| 271 |
with gr.Column():
|
| 272 |
input_images = gr.Gallery(
|
| 273 |
label="Input Images",
|
| 274 |
+
show_label=True,
|
| 275 |
+
type="pil",
|
| 276 |
interactive=True
|
| 277 |
)
|
| 278 |
with gr.Column():
|
| 279 |
result = gr.Gallery(
|
| 280 |
label="Result",
|
| 281 |
+
show_label=True,
|
| 282 |
type="pil"
|
| 283 |
)
|
| 284 |
use_output_btn = gr.Button(
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
run_button = gr.Button(
|
| 292 |
+
"Edit",
|
| 293 |
variant="primary"
|
| 294 |
)
|
| 295 |
|
|
|
|
| 322 |
minimum=256,
|
| 323 |
maximum=2048,
|
| 324 |
step=8,
|
| 325 |
+
value=512,
|
| 326 |
)
|
| 327 |
width = gr.Slider(
|
| 328 |
label="Width",
|
| 329 |
minimum=256,
|
| 330 |
maximum=2048,
|
| 331 |
step=8,
|
| 332 |
+
value=512,
|
| 333 |
)
|
| 334 |
rewrite_prompt = gr.Checkbox(label="Rewrite prompt", value=True)
|
| 335 |
|
| 336 |
+
# Hardcoded removal prompt
|
| 337 |
DEFAULT_EDIT_PROMPT = "remove acne, marks, black spots, blemishes"
|
| 338 |
|
| 339 |
gr.on(
|
|
|
|
| 368 |
outputs=[input_images]
|
| 369 |
)
|
| 370 |
|
| 371 |
+
# Update raw preview when input image changes
|
| 372 |
+
def preview_update(imgs, *args):
|
| 373 |
+
return get_img_html(imgs)
|
| 374 |
+
|
| 375 |
+
input_images.change(
|
| 376 |
+
preview_update,
|
| 377 |
+
inputs=[input_images],
|
| 378 |
+
outputs=[preview_html]
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
|
| 383 |
if __name__ == "__main__":
|
| 384 |
demo.launch()
|