Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -201,84 +201,47 @@ css = """
|
|
| 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:
|
| 213 |
-
font-size: 1.3em;
|
| 214 |
-
line-height: 1.4;
|
| 215 |
}
|
| 216 |
-
|
| 217 |
-
|
| 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(
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
| 270 |
with gr.Row():
|
| 271 |
with gr.Column():
|
| 272 |
input_images = gr.Gallery(
|
| 273 |
label="Input Images",
|
| 274 |
-
show_label=
|
| 275 |
-
type="pil",
|
| 276 |
interactive=True
|
| 277 |
)
|
| 278 |
with gr.Column():
|
| 279 |
result = gr.Gallery(
|
| 280 |
label="Result",
|
| 281 |
-
show_label=
|
| 282 |
type="pil"
|
| 283 |
)
|
| 284 |
use_output_btn = gr.Button(
|
|
@@ -322,18 +285,18 @@ with gr.Blocks(css=css) as demo:
|
|
| 322 |
minimum=256,
|
| 323 |
maximum=2048,
|
| 324 |
step=8,
|
| 325 |
-
value=
|
| 326 |
)
|
| 327 |
width = gr.Slider(
|
| 328 |
label="Width",
|
| 329 |
minimum=256,
|
| 330 |
maximum=2048,
|
| 331 |
step=8,
|
| 332 |
-
value=
|
| 333 |
)
|
| 334 |
rewrite_prompt = gr.Checkbox(label="Rewrite prompt", value=True)
|
| 335 |
|
| 336 |
-
#
|
| 337 |
DEFAULT_EDIT_PROMPT = "remove acne, marks, black spots, blemishes"
|
| 338 |
|
| 339 |
gr.on(
|
|
@@ -368,17 +331,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 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()
|
|
|
|
| 201 |
#col-container {
|
| 202 |
margin: 0 auto;
|
| 203 |
max-width: 1024px;
|
|
|
|
| 204 |
}
|
| 205 |
+
#logo-title {
|
|
|
|
| 206 |
text-align: center;
|
| 207 |
+
padding: 20px 0; /* Use padding instead of negative margins */
|
| 208 |
+
}
|
| 209 |
+
#logo-title img {
|
| 210 |
+
width: 400px;
|
| 211 |
+
}
|
| 212 |
+
#logo-title h2 {
|
| 213 |
font-style: italic;
|
| 214 |
color: #5b47d1;
|
| 215 |
+
margin: 0; /* Reset all margins */
|
| 216 |
+
padding: 0;
|
|
|
|
|
|
|
| 217 |
}
|
| 218 |
+
#edit_text {
|
| 219 |
+
margin-top: 10px; /* Use positive margin */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
"""
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
with gr.Blocks(css=css) as demo:
|
| 225 |
with gr.Column(elem_id="col-container"):
|
| 226 |
+
gr.HTML("""
|
| 227 |
+
<div id="logo-title">
|
| 228 |
+
<h2 style="font-style: italic;color: #5b47d1;margin-top: -27px !important;margin-left: 96px">
|
| 229 |
+
Upload face image and get your acne, marks, black spots, blemishes removed.
|
| 230 |
+
</h2>
|
| 231 |
+
</div>
|
| 232 |
+
""")
|
| 233 |
with gr.Row():
|
| 234 |
with gr.Column():
|
| 235 |
input_images = gr.Gallery(
|
| 236 |
label="Input Images",
|
| 237 |
+
show_label=False,
|
| 238 |
+
type="pil",
|
| 239 |
interactive=True
|
| 240 |
)
|
| 241 |
with gr.Column():
|
| 242 |
result = gr.Gallery(
|
| 243 |
label="Result",
|
| 244 |
+
show_label=False,
|
| 245 |
type="pil"
|
| 246 |
)
|
| 247 |
use_output_btn = gr.Button(
|
|
|
|
| 285 |
minimum=256,
|
| 286 |
maximum=2048,
|
| 287 |
step=8,
|
| 288 |
+
value=None,
|
| 289 |
)
|
| 290 |
width = gr.Slider(
|
| 291 |
label="Width",
|
| 292 |
minimum=256,
|
| 293 |
maximum=2048,
|
| 294 |
step=8,
|
| 295 |
+
value=None,
|
| 296 |
)
|
| 297 |
rewrite_prompt = gr.Checkbox(label="Rewrite prompt", value=True)
|
| 298 |
|
| 299 |
+
# Hardcode the removal prompt and do not show prompt input
|
| 300 |
DEFAULT_EDIT_PROMPT = "remove acne, marks, black spots, blemishes"
|
| 301 |
|
| 302 |
gr.on(
|
|
|
|
| 331 |
outputs=[input_images]
|
| 332 |
)
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
if __name__ == "__main__":
|
| 336 |
demo.launch()
|