Spaces:
Runtime error
Runtime error
File size: 871 Bytes
732b57d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import streamlit as st
import tensorflow as tf
import tensorflow_hub as hub
from ..image_utils import tensor_to_image
@st.cache
def load_model():
hub_handle = 'https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2'
# return hub_model
return hub.load(hub_handle)
def stylize_content_image(model, content_image_file, style_image_file):
try:
stylized_image = model(tf.constant(
content_image_file), tf.constant(style_image_file))[0]
return tensor_to_image(stylized_image) # stylized image
except:
stylized_image = model(tf.constant(
tf.convert_to_tensor(content_image_file[:, :, :, :3])
),
tf.constant(
tf.convert_to_tensor(style_image_file[:, :, :, :3])
)
)[0]
return tensor_to_image(stylized_image) # stylized image
|