| 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 | |
| import matplotlib.pyplot as plt | |
| i1 = gr.inputs.Image(shape=(256, 256)) | |
| i2 = gr.inputs.Slider(minimum=2, maximum=4, step=0.5, default=None, label="Scale for intensity") | |
| o1 = gr.outputs.Image() | |
| o2 = gr.outputs.Image() | |
| gen_model = load_model('256_model_250ep.h5') | |
| def colorify(pixels, slider_value): | |
| pixels = (pixels - 127.5) / 127.5 | |
| pixels = np.expand_dims(pixels, 0) | |
| gen_image = gen_model.predict(pixels) | |
| gen_image = (gen_image + 1) / (slider_value) | |
| return Image.fromarray((gen_image[0] * 255.0).astype(np.uint8)) | |
| title = "Colorify" | |
| description = "Recolor your images using this lite version of PIX2PIX GAN , model is trained on 700 randomly collected images from the internet with 256*256 pixels" | |
| examples=[['example1.png', 2],['example2.jpg', 2]] | |
| article = "<p style='text-align: center'>" | |
| gr.Interface(fn=colorify, inputs=[i1, i2], outputs=o1, title=title, description=description, article=article, examples=examples, enable_queue=True).launch() | |