import gradio as gr import spaces from image_gen_aux import UpscaleWithModel from image_gen_aux.utils import load_image from fastapi.middleware.cors import CORSMiddleware import math MODELS = { "4xNomosWebPhotoRealPLKSR": "Phips/4xNomosWebPhoto_RealPLKSR", "4xRealESRGAN": "luca115/4xRealESRGAN", "4xRealHATGANSharper": "luca115/Real_HAT_GAN_SHARPER", "4xSwinIRLarge": "luca115/4xSwinIRLarge", } def get_duration( image, model_selection ): width, height = image.size pixel = width * height if model_selection in ["4xNomosWebPhotoRealPLKSR", "4xRealESRGAN"]: return math.ceil((pixel * 10) / 1_000_000) + 3 else: return math.ceil((pixel * 30) / 1_000_000) + 3 @spaces.GPU(duration = get_duration) def upscale_image(image, model_selection): original = load_image(image) upscaler = UpscaleWithModel.from_pretrained(MODELS[model_selection]).to("cuda") image = upscaler(original, tiling=True, tile_width=1024, tile_height=1024) return original, image def clear_result(): return gr.update(value=None) title = """