Aditya757864 commited on
Commit
915ddca
·
1 Parent(s): d1f0f96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -27,8 +27,17 @@ my_string = "\n".join(my_list)
27
  text2 = "The application focuses on neural style transfer, where the style from a style image is applied to a content image."
28
 
29
  def perform_neural_transfer(content_image_input, style_image_input):
 
 
 
 
30
  # Load content images
31
  content_image = content_image_input.astype(np.float32)[np.newaxis, ...] / 255.
 
 
 
 
 
32
  style_image = style_image_input.astype(np.float32)[np.newaxis, ...] / 255.
33
 
34
  # Apply neural style transfer
@@ -38,6 +47,7 @@ def perform_neural_transfer(content_image_input, style_image_input):
38
  return tensor_to_image(stylized_image)
39
 
40
 
 
41
  app_interface = gr.Interface(
42
  fn=perform_neural_transfer,
43
  inputs=[content_image_input, style_image_input],
 
27
  text2 = "The application focuses on neural style transfer, where the style from a style image is applied to a content image."
28
 
29
  def perform_neural_transfer(content_image_input, style_image_input):
30
+ if content_image_input is None:
31
+ # Handle the case when content image is not provided
32
+ return PIL.Image.fromarray(np.zeros((1, 1, 3), dtype=np.uint8))
33
+
34
  # Load content images
35
  content_image = content_image_input.astype(np.float32)[np.newaxis, ...] / 255.
36
+
37
+ if style_image_input is None:
38
+ # Handle the case when style image is not provided
39
+ return tensor_to_image(content_image)
40
+
41
  style_image = style_image_input.astype(np.float32)[np.newaxis, ...] / 255.
42
 
43
  # Apply neural style transfer
 
47
  return tensor_to_image(stylized_image)
48
 
49
 
50
+
51
  app_interface = gr.Interface(
52
  fn=perform_neural_transfer,
53
  inputs=[content_image_input, style_image_input],