import gradio as gr import numpy as np from PIL import Image import torch from torchvision.transforms import ToTensor from torchvision import transforms from model import pixact # Load the ONNX model model_path = "./model_best.pth" # Replace with your model path transforms = transforms.Compose([ #transforms.Resize(size=(50, 50), antialias=True), transforms.ToTensor() ]) net = torch.load(model_path, map_location=torch.device('cpu')) net = net['arch'] net.eval() net.cpu() # Define the superresolution function def superresolve(image): # Preprocess the image image = transforms(image)[None,...] # Run inference output = pixact(net(image)) # Postprocess the output output = output.permute(0,2,3,1)[0].data.numpy() output *= 255.0 output = output.clip(0, 255) output = Image.fromarray(np.uint8(output)) return output # Define the Gradio interface interface = gr.Interface( fn=superresolve, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil"), title="Super Resolution", description="Upload an image to upscale its resolution.", allow_flagging=False, ) # Launch the Gradio app interface.launch() # impath = './image.jpg' # img = Image.open(impath).convert('RGB') # superresolve(img)