Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
inputs = gr.inputs.Image()
|
8 |
+
o1 = gr.outputs.Image()
|
9 |
+
o2 = gr.outputs.Image()
|
10 |
+
gen_model = load_model('generator_model.h5')
|
11 |
+
|
12 |
+
def colorify(inp):
|
13 |
+
|
14 |
+
pixels = load_img(inp, target_size=(512, 512))
|
15 |
+
pixels = img_to_array(pixels)
|
16 |
+
pixels = (pixels - 127.5) / 127.5
|
17 |
+
pixels = np.expand_dims(pixels, 0)
|
18 |
+
gen_image = gen_model.predict(pixels)
|
19 |
+
gen_image = (gen_image + 1) / 1.5
|
20 |
+
|
21 |
+
return Image.fromarray(gen_image[0]*255)
|
22 |
+
|
23 |
+
title = "Colorify"
|
24 |
+
description = "Recolor your images using this lite version of PIX2PIX GAN"
|
25 |
+
examples=[['example1.png'],['example2.jpg']]
|
26 |
+
article = "<p style='text-align: center'>"
|
27 |
+
|
28 |
+
gr.Interface(fn=colorify, inputs=inputs, outputs=[o1, o2], title=title, description=description, article=article, examples=examples, enable_queue=True).launch()
|
29 |
+
|