Spaces:
Runtime error
Runtime error
luca-martial
commited on
Commit
•
8e7e8df
1
Parent(s):
da45ac7
debug
Browse files
app.py
CHANGED
@@ -6,16 +6,23 @@ import numpy as np
|
|
6 |
|
7 |
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def stylize(content_image, style_image):
|
11 |
content_image = content_image.astype(np.float32) / 255.
|
12 |
style_image = style_image.astype(np.float32) / 255.
|
13 |
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
return
|
18 |
|
19 |
|
20 |
-
iface = gr.Interface(fn=stylize, inputs=["image", "image"], outputs="
|
21 |
iface.launch()
|
|
|
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 stylize(content_image, style_image):
|
18 |
content_image = content_image.astype(np.float32) / 255.
|
19 |
style_image = style_image.astype(np.float32) / 255.
|
20 |
|
21 |
+
outputs = hub_module(tf.constant(content_image), tf.constant(style_image))
|
22 |
+
stylized_image = outputs[0]
|
23 |
|
24 |
+
return tensor_to_image(stylized_image)
|
25 |
|
26 |
|
27 |
+
iface = gr.Interface(fn=stylize, inputs=["image", "image"], outputs="image")
|
28 |
iface.launch()
|