Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
import cv2 | |
import numpy as np | |
from basicsr.archs.srvgg_arch import SRVGGNetCompact | |
from realesrgan import RealESRGANer | |
# Modell-Konfiguration für realesr-general-x4v3.pth | |
model_path = 'realesr-general-x4v3.pth' | |
model = SRVGGNetCompact( | |
num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu' | |
) | |
upsampler = RealESRGANer( | |
scale=4, | |
model_path=model_path, | |
model=model, | |
tile=0, | |
tile_pad=10, | |
pre_pad=0, | |
half=True if torch.cuda.is_available() else False | |
) | |
def upscale(image): | |
try: | |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) | |
output, _ = upsampler.enhance(image, outscale=4) | |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB) | |
return output | |
except Exception as e: | |
return f"Fehler beim Upscaling: {e}" | |
demo = gr.Interface( | |
fn=upscale, | |
inputs=gr.Image(type="numpy"), | |
outputs=gr.Image(type="numpy"), | |
title="Real-ESRGAN Upscaler (x4)", | |
description="Lade ein Bild hoch, das mit Real-ESRGAN hochskaliert werden soll." | |
) | |
demo.launch() |