luca-martial commited on
Commit
46f4974
1 Parent(s): a80599f
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,11 +1,19 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
  import tensorflow_hub as hub
4
- import matplotlib.pylab as plt
5
  import numpy as np
6
 
7
  hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
8
 
 
 
 
 
 
 
 
 
9
  def load_img(path_to_img):
10
  max_dim = 512
11
  #img = tf.io.read_file(path_to_img)
@@ -24,8 +32,9 @@ def load_img(path_to_img):
24
 
25
 
26
 
27
- def stylize(content_path, style_path):
28
- content_image = plt.imread(content_path)
 
29
 
30
  #content_image = load_img(content_path)
31
  #style_image = load_img(style_path)
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import tensorflow_hub as hub
4
+ import matplotlib.pyplot as plt
5
  import numpy as np
6
 
7
  hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
8
 
9
+ def tensor_to_image(tensor):
10
+ tensor = tensor*255
11
+ tensor = np.array(tensor, dtype=np.uint8)
12
+ if np.ndim(tensor)>3:
13
+ assert tensor.shape[0] == 1
14
+ tensor = tensor[0]
15
+ return PIL.Image.fromarray(tensor)
16
+
17
  def load_img(path_to_img):
18
  max_dim = 512
19
  #img = tf.io.read_file(path_to_img)
 
32
 
33
 
34
 
35
+ def stylize(content_image, style_image):
36
+ content_image = load_img(content_image)
37
+ content_image = tensor_to_image(content_image)
38
 
39
  #content_image = load_img(content_path)
40
  #style_image = load_img(style_path)