Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -169,58 +169,54 @@ def image_properties(img):
|
|
| 169 |
return properties
|
| 170 |
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
with gr.Blocks(title="Real-ESRGAN Gradio Demo", theme="dark") as demo:
|
| 175 |
-
|
| 176 |
-
gr.Markdown(
|
| 177 |
-
"""# <div align="center"> Real-ESRGAN Demo for Image Restoration and Upscaling </div>
|
| 178 |
-
<div align="center"><img width="200" height="74" src="https://github.com/xinntao/Real-ESRGAN/raw/master/assets/realesrgan_logo.png"></div>
|
| 179 |
-
|
| 180 |
-
This Gradio Demo was built as my Final Project for **CS50's Introduction to Programming with Python**.
|
| 181 |
-
Please visit the [Real-ESRGAN GitHub page](https://github.com/xinntao/Real-ESRGAN) for detailed information about the project.
|
| 182 |
-
"""
|
| 183 |
-
)
|
| 184 |
-
|
| 185 |
-
with gr.Accordion("Options/Parameters"):
|
| 186 |
-
with gr.Row():
|
| 187 |
-
model_name = gr.Dropdown(label="Real-ESRGAN inference model to be used",
|
| 188 |
-
choices=["RealESRGAN_x4plus", "RealESRNet_x4plus", "RealESRGAN_x4plus_anime_6B",
|
| 189 |
-
"RealESRGAN_x2plus", "realesr-general-x4v3"],
|
| 190 |
-
value="realesr-general-x4v3", show_label=True)
|
| 191 |
-
denoise_strength = gr.Slider(label="Denoise Strength (Used only with the realesr-general-x4v3 model)",
|
| 192 |
-
minimum=0, maximum=1, step=0.1, value=0.5)
|
| 193 |
-
outscale = gr.Slider(label="Image Upscaling Factor",
|
| 194 |
-
minimum=1, maximum=10, step=1, value=2, show_label=True)
|
| 195 |
-
face_enhance = gr.Checkbox(label="Face Enhancement using GFPGAN (Doesn't work for anime images)",
|
| 196 |
-
value=False, show_label=True)
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
input_image_properties = gr.Textbox(label="Image Properties", max_lines=1)
|
| 202 |
-
output_image = gr.Image(label="Restored Image", image_mode="RGBA")
|
| 203 |
-
with gr.Row():
|
| 204 |
-
restore_btn = gr.Button("Restore Image")
|
| 205 |
-
reset_btn = gr.Button("Reset")
|
| 206 |
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
outputs=output_image)
|
| 212 |
-
reset_btn.click(fn=reset, inputs=[], outputs=[output_image, input_image])
|
| 213 |
-
# reset_btn.click(None, inputs=[], outputs=[input_image], _js="() => (null)\n")
|
| 214 |
-
# Undocumented method to clear a component's value using Javascript
|
| 215 |
-
|
| 216 |
-
gr.Markdown(
|
| 217 |
-
"""*Please note that support for animated GIFs is not yet implemented. Should an animated GIF is chosen for restoration,
|
| 218 |
-
the demo will output only the first frame saved in PNG format (to preserve probable transparency).*
|
| 219 |
-
"""
|
| 220 |
-
)
|
| 221 |
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
|
|
|
| 224 |
|
| 225 |
-
if __name__ == "__main__":
|
| 226 |
-
main()
|
|
|
|
| 169 |
return properties
|
| 170 |
|
| 171 |
|
| 172 |
+
# Gradio Interface
|
| 173 |
+
with gr.Blocks(title="Real-ESRGAN Gradio Demo", theme="dark") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
+
gr.Markdown(
|
| 176 |
+
"""# <div align="center"> Real-ESRGAN Demo for Image Restoration and Upscaling </div>
|
| 177 |
+
<div align="center"><img width="200" height="74" src="https://github.com/xinntao/Real-ESRGAN/raw/master/assets/realesrgan_logo.png"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
This Gradio Demo was built as my Final Project for **CS50's Introduction to Programming with Python**.
|
| 180 |
+
Please visit the [Real-ESRGAN GitHub page](https://github.com/xinntao/Real-ESRGAN) for detailed information about the project.
|
| 181 |
+
"""
|
| 182 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
with gr.Accordion("Options/Parameters"):
|
| 185 |
+
with gr.Row():
|
| 186 |
+
model_name = gr.Dropdown(label="Real-ESRGAN inference model to be used",
|
| 187 |
+
choices=["RealESRGAN_x4plus", "RealESRNet_x4plus", "RealESRGAN_x4plus_anime_6B",
|
| 188 |
+
"RealESRGAN_x2plus", "realesr-general-x4v3"],
|
| 189 |
+
value="realesr-general-x4v3", show_label=True)
|
| 190 |
+
denoise_strength = gr.Slider(label="Denoise Strength (Used only with the realesr-general-x4v3 model)",
|
| 191 |
+
minimum=0, maximum=1, step=0.1, value=0.5)
|
| 192 |
+
outscale = gr.Slider(label="Image Upscaling Factor",
|
| 193 |
+
minimum=1, maximum=10, step=1, value=2, show_label=True)
|
| 194 |
+
face_enhance = gr.Checkbox(label="Face Enhancement using GFPGAN (Doesn't work for anime images)",
|
| 195 |
+
value=False, show_label=True)
|
| 196 |
+
|
| 197 |
+
with gr.Row():
|
| 198 |
+
with gr.Group():
|
| 199 |
+
input_image = gr.Image(label="Source Image", type="pil", image_mode="RGBA")
|
| 200 |
+
input_image_properties = gr.Textbox(label="Image Properties", max_lines=1)
|
| 201 |
+
output_image = gr.Image(label="Restored Image", image_mode="RGBA")
|
| 202 |
+
with gr.Row():
|
| 203 |
+
restore_btn = gr.Button("Restore Image")
|
| 204 |
+
reset_btn = gr.Button("Reset")
|
| 205 |
+
|
| 206 |
+
# Event listeners:
|
| 207 |
+
input_image.change(fn=image_properties, inputs=input_image, outputs=input_image_properties)
|
| 208 |
+
restore_btn.click(fn=realesrgan,
|
| 209 |
+
inputs=[input_image, model_name, denoise_strength, face_enhance, outscale],
|
| 210 |
+
outputs=output_image)
|
| 211 |
+
reset_btn.click(fn=reset, inputs=[], outputs=[output_image, input_image])
|
| 212 |
+
# reset_btn.click(None, inputs=[], outputs=[input_image], _js="() => (null)\n")
|
| 213 |
+
# Undocumented method to clear a component's value using Javascript
|
| 214 |
+
|
| 215 |
+
gr.Markdown(
|
| 216 |
+
"""*Please note that support for animated GIFs is not yet implemented. Should an animated GIF is chosen for restoration,
|
| 217 |
+
the demo will output only the first frame saved in PNG format (to preserve probable transparency).*
|
| 218 |
+
"""
|
| 219 |
+
)
|
| 220 |
|
| 221 |
+
demo.launch()
|
| 222 |
|
|
|
|
|
|