ohayonguy
commited on
Commit
·
b1e0e58
1
Parent(s):
c64779b
improved interface
Browse files
app.py
CHANGED
|
@@ -193,15 +193,14 @@ def inference(
|
|
| 193 |
return output, restored_faces if len(restored_faces) > 1 else None
|
| 194 |
|
| 195 |
|
|
|
|
| 196 |
intro = """
|
| 197 |
-
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration</h1>
|
| 198 |
<h3 style="margin-bottom: 10px; text-align: center;">
|
| 199 |
<a href="https://arxiv.org/abs/2410.00418">[Paper]</a> |
|
| 200 |
<a href="https://pmrf-ml.github.io/">[Project Page]</a> |
|
| 201 |
<a href="https://github.com/ohayonguy/PMRF">[Code]</a>
|
| 202 |
</h3>
|
| 203 |
-
|
| 204 |
-
markdown_top = """
|
| 205 |
Gradio demo for the blind face image restoration version of [Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration](https://arxiv.org/abs/2410.00418).
|
| 206 |
You may use this demo to enhance the quality of any image which contains faces.
|
| 207 |
|
|
@@ -212,8 +211,6 @@ Please refer to our project's page for more details: https://pmrf-ml.github.io/.
|
|
| 212 |
1. Our model is designed to restore aligned face images, where there is *only one* face in the image, and the face is centered and aligned. Here, however, we incorporate mechanisms that allow restoring the quality of *any* image that contains *any* number of faces. Thus, the resulting quality of such general images is not guaranteed.
|
| 213 |
2. If the faces in your image are not aligned, make sure that the checkbox "The input is an aligned face image" in *not* marked.
|
| 214 |
3. Too large images may result in out-of-memory error.
|
| 215 |
-
|
| 216 |
-
---
|
| 217 |
"""
|
| 218 |
|
| 219 |
article = r"""
|
|
@@ -249,85 +246,49 @@ css = """
|
|
| 249 |
}
|
| 250 |
"""
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
[42, False, "examples/01.png", False, 1, 25],
|
| 296 |
-
[42, False, "examples/03.jpg", False, 2, 25],
|
| 297 |
-
[42, False, "examples/00000055.png", True, 1, 25],
|
| 298 |
-
[42, False, "examples/00000085.png", True, 1, 25],
|
| 299 |
-
[42, False, "examples/00000113.png", True, 1, 25],
|
| 300 |
-
[42, False, "examples/00000137.png", True, 1, 25],
|
| 301 |
-
],
|
| 302 |
-
fn=inference,
|
| 303 |
-
inputs=[
|
| 304 |
-
seed,
|
| 305 |
-
randomize_seed,
|
| 306 |
-
input_im,
|
| 307 |
-
aligned,
|
| 308 |
-
upscale_factor,
|
| 309 |
-
num_inference_steps,
|
| 310 |
-
],
|
| 311 |
-
outputs=[result, gallery],
|
| 312 |
-
cache_examples="lazy",
|
| 313 |
-
)
|
| 314 |
-
|
| 315 |
-
gr.Markdown(article)
|
| 316 |
-
gr.on(
|
| 317 |
-
[run_button.click],
|
| 318 |
-
fn=inference,
|
| 319 |
-
inputs=[
|
| 320 |
-
seed,
|
| 321 |
-
randomize_seed,
|
| 322 |
-
input_im,
|
| 323 |
-
aligned,
|
| 324 |
-
upscale_factor,
|
| 325 |
-
num_inference_steps,
|
| 326 |
-
],
|
| 327 |
-
outputs=[result, gallery],
|
| 328 |
-
# show_api=False,
|
| 329 |
-
# show_progress="minimal",
|
| 330 |
-
)
|
| 331 |
|
| 332 |
demo.queue()
|
| 333 |
demo.launch(state_session_capacity=15)
|
|
|
|
| 193 |
return output, restored_faces if len(restored_faces) > 1 else None
|
| 194 |
|
| 195 |
|
| 196 |
+
title = "Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration"
|
| 197 |
intro = """
|
|
|
|
| 198 |
<h3 style="margin-bottom: 10px; text-align: center;">
|
| 199 |
<a href="https://arxiv.org/abs/2410.00418">[Paper]</a> |
|
| 200 |
<a href="https://pmrf-ml.github.io/">[Project Page]</a> |
|
| 201 |
<a href="https://github.com/ohayonguy/PMRF">[Code]</a>
|
| 202 |
</h3>
|
| 203 |
+
|
|
|
|
| 204 |
Gradio demo for the blind face image restoration version of [Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration](https://arxiv.org/abs/2410.00418).
|
| 205 |
You may use this demo to enhance the quality of any image which contains faces.
|
| 206 |
|
|
|
|
| 211 |
1. Our model is designed to restore aligned face images, where there is *only one* face in the image, and the face is centered and aligned. Here, however, we incorporate mechanisms that allow restoring the quality of *any* image that contains *any* number of faces. Thus, the resulting quality of such general images is not guaranteed.
|
| 212 |
2. If the faces in your image are not aligned, make sure that the checkbox "The input is an aligned face image" in *not* marked.
|
| 213 |
3. Too large images may result in out-of-memory error.
|
|
|
|
|
|
|
| 214 |
"""
|
| 215 |
|
| 216 |
article = r"""
|
|
|
|
| 246 |
}
|
| 247 |
"""
|
| 248 |
|
| 249 |
+
demo = gr.Interface(
|
| 250 |
+
inference,
|
| 251 |
+
[
|
| 252 |
+
gr.Image(label="Input", type="filepath", show_label=True),
|
| 253 |
+
gr.Checkbox(label="Randomize seed", value=True),
|
| 254 |
+
gr.Checkbox(label="The input is an aligned face image", value=False),
|
| 255 |
+
gr.Slider(
|
| 256 |
+
label="Number of Inference Steps",
|
| 257 |
+
minimum=1,
|
| 258 |
+
maximum=200,
|
| 259 |
+
step=1,
|
| 260 |
+
value=25,
|
| 261 |
+
scale=1,
|
| 262 |
+
),
|
| 263 |
+
gr.Slider(
|
| 264 |
+
label="Scale factor (applicable to non-aligned face images)",
|
| 265 |
+
minimum=1,
|
| 266 |
+
maximum=4,
|
| 267 |
+
step=0.1,
|
| 268 |
+
value=1,
|
| 269 |
+
scale=1,
|
| 270 |
+
),
|
| 271 |
+
gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42, scale=1),
|
| 272 |
+
],
|
| 273 |
+
[
|
| 274 |
+
gr.Image(label="Output", type="numpy", show_label=True, format="png"),
|
| 275 |
+
gr.Gallery(
|
| 276 |
+
label="Restored faces gallery", type="numpy", show_label=True, format="png",
|
| 277 |
+
),
|
| 278 |
+
],
|
| 279 |
+
title=title,
|
| 280 |
+
description=intro,
|
| 281 |
+
article=article,
|
| 282 |
+
examples=[
|
| 283 |
+
[42, False, "examples/01.png", False, 1, 25],
|
| 284 |
+
[42, False, "examples/03.jpg", False, 2, 25],
|
| 285 |
+
[42, False, "examples/00000055.png", True, 1, 25],
|
| 286 |
+
[42, False, "examples/00000085.png", True, 1, 25],
|
| 287 |
+
[42, False, "examples/00000113.png", True, 1, 25],
|
| 288 |
+
[42, False, "examples/00000137.png", True, 1, 25],
|
| 289 |
+
],
|
| 290 |
+
theme=gr.themes.Soft(),
|
| 291 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
demo.queue()
|
| 294 |
demo.launch(state_session_capacity=15)
|