Franco Astegiano commited on
Commit
5f8fdd6
1 Parent(s): 0c4feb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -164,7 +164,7 @@ is the same as the content image shape.
164
 
165
  # Stylize content image with given style image.
166
  # This is pretty fast within a few milliseconds on a GPU.
167
-
168
  def modify(imageinput,style_input):
169
  content_image = load_image(imageinput, content_img_size)
170
  style_image = load_image(style_input, style_img_size)
@@ -172,6 +172,16 @@ def modify(imageinput,style_input):
172
  #show_n([content_image, style_image], ['Content image', 'Style image'])
173
  outputs = hub_module(tf.constant(imageinput), tf.constant(style_input))
174
  return outputs[0]
 
 
 
 
 
 
 
 
 
 
175
  #stylized_image = outputs[0]
176
 
177
  # Visualize input images and the generated stylized image.
@@ -181,7 +191,7 @@ def modify(imageinput,style_input):
181
  # Gradio app
182
 
183
  #label = gr.outputs.Image(modify(content_image_input, style_image_input))
184
- app_interface = gr.Interface(modify,
185
  inputs=[content_image_input, style_image_input],
186
  outputs='image',
187
  title="Fast Neural Style Transfer",
 
164
 
165
  # Stylize content image with given style image.
166
  # This is pretty fast within a few milliseconds on a GPU.
167
+ '''
168
  def modify(imageinput,style_input):
169
  content_image = load_image(imageinput, content_img_size)
170
  style_image = load_image(style_input, style_img_size)
 
172
  #show_n([content_image, style_image], ['Content image', 'Style image'])
173
  outputs = hub_module(tf.constant(imageinput), tf.constant(style_input))
174
  return outputs[0]
175
+ '''
176
+ def perform_style_transfer(content_image, style_image):
177
+
178
+ content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
179
+ style_image = tf.convert_to_tensor(style_image, np.float32)[tf.newaxis, ...] / 255.
180
+
181
+ output = style_transfer_model(content_image, style_image)
182
+ stylized_image = output[0]
183
+
184
+ return Image.fromarray(np.uint8(stylized_image[0] * 255))
185
  #stylized_image = outputs[0]
186
 
187
  # Visualize input images and the generated stylized image.
 
191
  # Gradio app
192
 
193
  #label = gr.outputs.Image(modify(content_image_input, style_image_input))
194
+ app_interface = gr.Interface(perform_style_transfer,
195
  inputs=[content_image_input, style_image_input],
196
  outputs='image',
197
  title="Fast Neural Style Transfer",