Aravind Sundaresan commited on
Commit
f87c6a5
1 Parent(s): 37aaf26

Added application file

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ import tensorflow_hub as hub
6
+
7
+ style_transfer_model = hub.load("https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2")
8
+
9
+
10
+ def perform_style_transfer(content_image, style_image):
11
+
12
+ content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
13
+ style_image = tf.convert_to_tensor(style_image, np.float32)[tf.newaxis, ...] / 255.
14
+
15
+ output = style_transfer_model(content_image, style_image)
16
+ stylized_image = output[0]
17
+
18
+ return Image.fromarray(np.uint8(stylized_image[0] * 255))
19
+
20
+
21
+ content_image_input = gr.inputs.Image()
22
+ style_image_input = gr.inputs.Image(shape=(256, 256))
23
+
24
+ interface = gr.Interface(fn=perform_style_transfer,
25
+ inputs=[content_image_input, style_image_input],
26
+ outputs="image")
27
+ Interface.launch()