Spaces:
Runtime error
Runtime error
luca-martial
commited on
Commit
·
e3910d5
1
Parent(s):
dc39883
debug
Browse files
app.py
CHANGED
@@ -1,14 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import tensorflow_hub as hub
|
|
|
|
|
4 |
|
5 |
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
6 |
|
7 |
-
def stylize(
|
8 |
-
content_image =
|
9 |
-
style_image =
|
|
|
|
|
|
|
|
|
10 |
stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
|
11 |
return tensor_to_image(stylized_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
iface = gr.Interface(fn=stylize, inputs=["image", "image"], outputs="image")
|
14 |
iface.launch()
|
|
|
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 stylize(content_image_path, style_image_path):
|
10 |
+
content_image = plt.imread(content_image_path)
|
11 |
+
style_image = plt.imread(style_image_path)
|
12 |
+
content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.
|
13 |
+
style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.
|
14 |
+
style_image = tf.image.resize(style_image, (256, 256))
|
15 |
+
|
16 |
stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
|
17 |
return tensor_to_image(stylized_image)
|
18 |
+
|
19 |
+
|
20 |
+
# Load content and style images (see example in the attached colab).
|
21 |
+
#content_image = plt.imread(content_image_path)
|
22 |
+
#style_image = plt.imread(style_image_path)
|
23 |
+
|
24 |
+
# Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]. Example using numpy:
|
25 |
+
#content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.
|
26 |
+
#style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.
|
27 |
+
|
28 |
+
# Optionally resize the images. It is recommended that the style image is about
|
29 |
+
# 256 pixels (this size was used when training the style transfer network).
|
30 |
+
# The content image can be any size.
|
31 |
+
# style_image = tf.image.resize(style_image, (256, 256))
|
32 |
+
|
33 |
|
34 |
iface = gr.Interface(fn=stylize, inputs=["image", "image"], outputs="image")
|
35 |
iface.launch()
|