from PIL import Image import tensorflow import gradio as gr from tensorflow.keras.models import load_model model = load_model('model') def infer(img): cartoonGAN = model.signatures["serving_default"] img = np.array(img.convert("RGB")) img = np.expand_dims(img, 0).astype(np.float32) / 127.5 - 1 out = cartoonGAN(tf.constant(img))['output_1'] out = ((out.numpy().squeeze() + 1) * 127.5).astype(np.uint8) return out title = "CartoonGAN" description = "Gradio Demo for AnimeGanv2 Face Portrait. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please use a cropped portrait picture for best results similar to the examples below." #description = "Gradio Demo for AnimeGanv2 Face Portrait. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please use a cropped portrait picture for best results similar to the examples below." iface = gr.Interface(infer, gr.inputs.Image(type="pil"), "image",title=title,description=description) iface.launch()