Spaces:
Runtime error
Runtime error
from cgitb import enable | |
from ctypes.wintypes import HFONT | |
import os | |
import sys | |
import torch | |
import gradio as gr | |
import numpy as np | |
import torchvision.transforms as transforms | |
from torch.autograd import Variable | |
from huggingface_hub import hf_hub_download | |
from PIL import Image | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.getLogger(__name__) | |
MODEL_PATH = "models" | |
COLOUR_MODEL = "RGB" | |
MODEL_REPO = "NDugar/horse_to_zebra_cycle_GAN" | |
MODEL_FILE = "h2z-85epoch.pth" | |
model_hfhub = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE) | |
enable_gpu = torch.cuda.is_available() | |
map_location = torch.device("cuda") if enable_gpu else "cpu" | |
from huggingface_hub import hf_hub_download | |
from fastai.learner import load_learner | |
model = load_learner( | |
hf_hub_download("NDugar/horse_to_zebra_cycle_GAN", "h2z-85epoch.pth") | |
) | |
def generate_img(img_path): | |
img = tf.io.read_file(img_path) | |
img = tf.image.decode_png(img) | |
img = tf.expand_dims(img, axis=0) | |
img = preprocess_test_image(img) | |
prediction = model(img, training=False)[0].numpy() | |
return prediction | |
image = gr.inputs.Image(type="filepath") | |
op = gr.outputs.Image(type="numpy") | |
iface = gr.Interface( | |
generate_img, | |
image, | |
op, | |
title="CycleGAN-using UPIT", | |
description='CycleGAN model using Horse to Zebra using UPIT - https://github.com/tmabraham/UPIT' | |
) | |
iface.launch(cache_examples=False) |