Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
app.pyimport gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
from realesrgan import RealESRGANer
|
| 4 |
+
|
| 5 |
+
# Khởi tạo mô hình Real-ESRGAN
|
| 6 |
+
model_path = "weights/RealESRGAN_x4plus.pth" # Đảm bảo đã tải mô hình
|
| 7 |
+
upscaler = RealESRGANer(
|
| 8 |
+
scale=4,
|
| 9 |
+
model_path=model_path,
|
| 10 |
+
model=None,
|
| 11 |
+
tile=0,
|
| 12 |
+
tile_pad=10,
|
| 13 |
+
pre_pad=0,
|
| 14 |
+
half=True, # Sử dụng FP16 nếu có GPU
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def upscale_image(image):
|
| 18 |
+
try:
|
| 19 |
+
output, _ = upscaler.enhance(image, outscale=4)
|
| 20 |
+
return output
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return str(e)
|
| 23 |
+
|
| 24 |
+
# Giao diện Gradio
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=upscale_image,
|
| 27 |
+
inputs=gr.Image(type="numpy", label="Upload Image"),
|
| 28 |
+
outputs=gr.Image(type="numpy", label="Upscaled Image"),
|
| 29 |
+
title="Real-ESRGAN Upscaler",
|
| 30 |
+
description="Upload an image to upscale it using Real-ESRGAN."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
iface.launch()
|