bhadresh-savani commited on
Commit
7c82ec5
1 Parent(s): ae0e4e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -5
app.py CHANGED
@@ -1,11 +1,46 @@
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def sketch_to_shoes(img):
4
- # Implement sketch recognition model here...
5
- # Return labels and confidences as dictionary
6
- return img
7
 
8
  img = gr.inputs.Image(shape=(256,256))
9
  plot = gr.outputs.Image(type="plot")
10
 
11
- iface = gr.Interface(fn=sketch_to_shoes, inputs="sketchpad", title = "Pix2Pix Sketch to Shoes", outputs=plot).launch()
 
 
 
1
+ import tensorflow as tf
2
+ import pathlib
3
  import gradio as gr
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 = "Conditional GAN model that translates image-to-image."
45
+ gr.Interface(generate_images, inputs = img, outputs = plot,
46
+ title = "Pix2Pix Shoes Reconstructor", description = description, examples = [["./img.png"]]).launch()