Spaces:
Running
on
Zero
Running
on
Zero
ohayonguy
commited on
Commit
•
4942d84
1
Parent(s):
5cd4a52
improved interface
Browse files
app.py
CHANGED
@@ -138,24 +138,26 @@ def inference(seed, randomize_seed, img, aligned, scale, num_flow_steps):
|
|
138 |
model_rootpath=None)
|
139 |
|
140 |
has_aligned = True if aligned == 'Yes' else False
|
141 |
-
|
142 |
paste_back=True, num_flow_steps=num_flow_steps, scale=scale)
|
143 |
if has_aligned:
|
144 |
output = restored_aligned[0]
|
|
|
145 |
else:
|
146 |
output = restored_img
|
|
|
147 |
|
148 |
save_path = f'output/out.png'
|
149 |
cv2.imwrite(save_path, output)
|
150 |
|
151 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
152 |
h, w = output.shape[0:2]
|
153 |
-
|
154 |
-
|
155 |
-
return [[
|
156 |
|
157 |
intro = """
|
158 |
-
<
|
159 |
<h3 style="margin-bottom: 10px; text-align: center;">
|
160 |
<a href="https://arxiv.org/abs/2410.00418">[Paper]</a> |
|
161 |
<a href="https://pmrf-ml.github.io/">[Project Page]</a> |
|
@@ -171,37 +173,14 @@ Please refer to our project's page for more details: https://pmrf-ml.github.io/.
|
|
171 |
|
172 |
You may use this demo to enhance the quality of any image which contains faces.
|
173 |
|
174 |
-
|
175 |
-
2. Otherwise, your image may contain any number of faces (>=1), and the quality of each face will be enhanced separately.
|
176 |
|
177 |
-
*Notes
|
178 |
|
179 |
1. Our model is designed to restore aligned face images, but here 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.
|
180 |
2. Images that are too large won't work due to memory constraints.
|
181 |
"""
|
182 |
|
183 |
-
#
|
184 |
-
# title = "Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration"
|
185 |
-
#
|
186 |
-
# description = r"""
|
187 |
-
# Gradio demo for the blind face image restoration version of <a href='https://arxiv.org/abs/2410.00418' target='_blank'><b>Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration</b></a>.
|
188 |
-
#
|
189 |
-
# Please refer to our project's page for more details: https://pmrf-ml.github.io/.
|
190 |
-
#
|
191 |
-
# ---
|
192 |
-
#
|
193 |
-
# You may use this demo to enhance the quality of any image which contains faces.
|
194 |
-
#
|
195 |
-
# 1. If your input image has only one face and it is aligned, please mark "Yes" to the answer below.
|
196 |
-
# 2. Otherwise, your image may contain any number of faces (>=1), and the quality of each face will be enhanced separately.
|
197 |
-
#
|
198 |
-
# <b>NOTEs</b>:
|
199 |
-
#
|
200 |
-
# 1. Our model is designed to restore aligned face images, but here 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.
|
201 |
-
# 2. Images that are too large won't work due to memory constraints.
|
202 |
-
# """
|
203 |
-
|
204 |
-
|
205 |
article = r"""
|
206 |
|
207 |
If you find our work useful, please help to ⭐ our <a href='https://github.com/ohayonguy/PMRF' target='_blank'>GitHub repository</a>. Thanks!
|
@@ -235,23 +214,11 @@ css = """
|
|
235 |
margin: 0 auto;
|
236 |
max-width: 512px;
|
237 |
}
|
238 |
-
#run-button {
|
239 |
-
background-color: #FFA500; /* Orange */
|
240 |
-
color: white;
|
241 |
-
border: none;
|
242 |
-
padding: 10px 24px;
|
243 |
-
font-size: 16px;
|
244 |
-
cursor: pointer;
|
245 |
-
border-radius: 8px; /* Optional: Makes the button corners rounded */
|
246 |
-
}
|
247 |
-
#run-button:hover {
|
248 |
-
background-color: #e69500; /* Darker orange on hover */
|
249 |
-
}
|
250 |
"""
|
251 |
|
252 |
|
253 |
|
254 |
-
with gr.Blocks(css=css) as demo:
|
255 |
gr.HTML(intro)
|
256 |
gr.Markdown(markdown_top)
|
257 |
|
|
|
138 |
model_rootpath=None)
|
139 |
|
140 |
has_aligned = True if aligned == 'Yes' else False
|
141 |
+
cropped_face, restored_aligned, restored_img = enhance_face(img, face_helper, has_aligned, only_center_face=False,
|
142 |
paste_back=True, num_flow_steps=num_flow_steps, scale=scale)
|
143 |
if has_aligned:
|
144 |
output = restored_aligned[0]
|
145 |
+
input = cropped_face[0]
|
146 |
else:
|
147 |
output = restored_img
|
148 |
+
input = cropped_face
|
149 |
|
150 |
save_path = f'output/out.png'
|
151 |
cv2.imwrite(save_path, output)
|
152 |
|
153 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
154 |
h, w = output.shape[0:2]
|
155 |
+
input = cv2.cvtColor(input, cv2.COLOR_BGR2RGB)
|
156 |
+
input = cv2.resize(input, (h, w), interpolation=cv2.INTER_LINEAR)
|
157 |
+
return [[input, output, seed], save_path]
|
158 |
|
159 |
intro = """
|
160 |
+
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">Posterior-Mean Rectified Flow: Towards Minimum MSE Photo-Realistic Image Restoration</h1>
|
161 |
<h3 style="margin-bottom: 10px; text-align: center;">
|
162 |
<a href="https://arxiv.org/abs/2410.00418">[Paper]</a> |
|
163 |
<a href="https://pmrf-ml.github.io/">[Project Page]</a> |
|
|
|
173 |
|
174 |
You may use this demo to enhance the quality of any image which contains faces.
|
175 |
|
176 |
+
If your input image has only one face and it is aligned, please mark "Yes" to the answer below. Otherwise, your image may contain any number of faces (>=1), and the quality of each face will be enhanced separately.
|
|
|
177 |
|
178 |
+
*Notes* :
|
179 |
|
180 |
1. Our model is designed to restore aligned face images, but here 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.
|
181 |
2. Images that are too large won't work due to memory constraints.
|
182 |
"""
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
article = r"""
|
185 |
|
186 |
If you find our work useful, please help to ⭐ our <a href='https://github.com/ohayonguy/PMRF' target='_blank'>GitHub repository</a>. Thanks!
|
|
|
214 |
margin: 0 auto;
|
215 |
max-width: 512px;
|
216 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
"""
|
218 |
|
219 |
|
220 |
|
221 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
222 |
gr.HTML(intro)
|
223 |
gr.Markdown(markdown_top)
|
224 |
|