|
import gradio as gr |
|
import numpy as np |
|
from tensorflow.keras.preprocessing.image import load_img, img_to_array |
|
from tensorflow.keras.models import load_model |
|
from PIL import Image |
|
|
|
inputs = gr.inputs.Image() |
|
o1 = gr.outputs.Image() |
|
o2 = gr.outputs.Image() |
|
gen_model = load_model('generator_model.h5') |
|
|
|
def colorify(inp): |
|
|
|
pixels = load_img(inp, target_size=(512, 512)) |
|
pixels = img_to_array(pixels) |
|
pixels = (pixels - 127.5) / 127.5 |
|
pixels = np.expand_dims(pixels, 0) |
|
gen_image = gen_model.predict(pixels) |
|
gen_image = (gen_image + 1) / 1.5 |
|
|
|
return Image.fromarray(gen_image[0]*255) |
|
|
|
title = "Colorify" |
|
description = "Recolor your images using this lite version of PIX2PIX GAN" |
|
examples=[['example1.png'],['example2.jpg']] |
|
article = "<p style='text-align: center'>" |
|
|
|
gr.Interface(fn=colorify, inputs=inputs, outputs=[o1, o2], title=title, description=description, article=article, examples=examples, enable_queue=True).launch() |
|
|