Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
from realesrgan import RealESRGANer
|
|
|
|
| 4 |
|
| 5 |
# Initialize Real-ESRGAN
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
# Enhance image
|
| 21 |
-
output, _ =
|
|
|
|
| 22 |
return Image.fromarray(output)
|
| 23 |
|
|
|
|
| 24 |
demo = gr.Interface(
|
| 25 |
-
fn=
|
| 26 |
inputs=gr.Image(type="pil", label="Input Image"),
|
| 27 |
-
outputs=gr.Image(type="pil", label="Enhanced
|
| 28 |
-
title="Professional Image Enhancement"
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
from realesrgan import RealESRGANer
|
| 5 |
+
from basicsr.archs.rrdbnet_arch import RRDBNet
|
| 6 |
|
| 7 |
# Initialize Real-ESRGAN
|
| 8 |
+
def init_enhancer():
|
| 9 |
+
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
|
| 10 |
+
return RealESRGANer(
|
| 11 |
+
scale=4,
|
| 12 |
+
model_path="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
|
| 13 |
+
model=model,
|
| 14 |
+
tile=400,
|
| 15 |
+
tile_pad=10,
|
| 16 |
+
pre_pad=0,
|
| 17 |
+
half=False
|
| 18 |
+
)
|
| 19 |
|
| 20 |
+
enhancer = init_enhancer()
|
| 21 |
+
|
| 22 |
+
def enhance_image(input_img):
|
| 23 |
+
# Convert to numpy array
|
| 24 |
+
img_array = np.array(input_img)
|
| 25 |
|
| 26 |
# Enhance image
|
| 27 |
+
output, _ = enhancer.enhance(img_array, outscale=2) # 2x upscale
|
| 28 |
+
|
| 29 |
return Image.fromarray(output)
|
| 30 |
|
| 31 |
+
# Gradio interface
|
| 32 |
demo = gr.Interface(
|
| 33 |
+
fn=enhance_image,
|
| 34 |
inputs=gr.Image(type="pil", label="Input Image"),
|
| 35 |
+
outputs=gr.Image(type="pil", label="Enhanced"),
|
| 36 |
+
title="Professional Image Enhancement",
|
| 37 |
+
examples=["example.jpg"] if os.path.exists("example.jpg") else None,
|
| 38 |
+
allow_flagging="never"
|
| 39 |
)
|
| 40 |
|
| 41 |
demo.launch()
|