Spaces:
Runtime error
Runtime error
File size: 1,240 Bytes
2a0c22c f1a9b07 82b825a c323260 2a0c22c 243c318 689dcd0 82b825a 54b4741 f1a9b07 82b825a 54b4741 f1a9b07 243c318 c323260 f1a9b07 82b825a f1a9b07 243c318 f1a9b07 82b825a b00c9f5 f1a9b07 243c318 82b825a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 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) |