Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import pathlib
|
3 |
+
import gradio as gradio
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from huggingface_hub import from_pretrained_keras
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
# Normalizing the images to [-1, 1]
|
9 |
+
def normalize_test(input_image):
|
10 |
+
input_image = tf.cast(input_image, tf.float32)
|
11 |
+
input_image = (input_image / 127.5) - 1
|
12 |
+
return input_image
|
13 |
+
|
14 |
+
def resize(input_image, height, width):
|
15 |
+
input_image = tf.image.resize(input_image, [height, width],
|
16 |
+
method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
|
17 |
+
return input_image
|
18 |
+
|
19 |
+
def load_image_infer(image_file):
|
20 |
+
input_image = resize(image_file, 256, 256)
|
21 |
+
input_image = normalize_test(input_image)
|
22 |
+
|
23 |
+
return input_image
|
24 |
+
|
25 |
+
def generate_images(test_input):
|
26 |
+
test_input = load_image_infer(test_input)
|
27 |
+
prediction = generator(np.expand_dims(test_input, axis=0), training=True)
|
28 |
+
fig = plt.figure(figsize=(128, 128))
|
29 |
+
title = ['Predicted Image']
|
30 |
+
|
31 |
+
plt.title('Predicted Image')
|
32 |
+
# Getting the pixel values in the [0, 1] range to plot.
|
33 |
+
plt.imshow(prediction[0,:,:,:] * 0.5 + 0.5)
|
34 |
+
plt.axis('off')
|
35 |
+
return fig
|
36 |
+
|
37 |
+
|
38 |
+
generator = from_pretrained_keras("keras-io/pix2pix-generator")
|
39 |
+
|
40 |
+
|
41 |
+
img = gr.inputs.Image(shape=(256,256))
|
42 |
+
plot = gr.outputs.Image(type="plot")
|
43 |
+
|
44 |
+
description = "Pix2Pix Facade Reconstructor"
|
45 |
+
gr.Interface(generate_images, inputs = img, outputs = plot,
|
46 |
+
title = "Pix2Pix Facade Reconstructor", description = description, examples = [["img.png"]]).launch(debug=True)
|