File size: 904 Bytes
f87c6a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5ecde4
f87c6a5
 
b5ecde4
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
import gradio as gr
import numpy as np
from PIL import Image
import tensorflow as tf
import tensorflow_hub as hub

style_transfer_model = hub.load("https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2")

def perform_style_transfer(content_image, style_image):
    
    content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
    style_image = tf.convert_to_tensor(style_image, np.float32)[tf.newaxis, ...] / 255.
    
    output = style_transfer_model(content_image, style_image)
    stylized_image = output[0]
    
    return Image.fromarray(np.uint8(stylized_image[0] * 255))


content_image_input = gr.inputs.Image()
style_image_input = gr.inputs.Image(shape=(256, 256))

app_interface = gr.Interface(fn=perform_style_transfer,
                  inputs=[content_image_input, style_image_input],
                  outputs="image")
app_interface.launch()