Legola commited on
Commit
dcbc12e
·
1 Parent(s): 1780770

Update app.py

Browse files

Added transform to the code

Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -15,6 +15,17 @@ import torchvision.transforms.functional as TF
15
  from PIL import Image
16
  import numpy as np
17
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  #Defining the predict function
20
  def style_transfer(cont_img,styl_img):
 
15
  from PIL import Image
16
  import numpy as np
17
 
18
+ def image_transform(image):
19
+ if isinstance(image, str):
20
+ # If image is a path to a file, open it using PIL
21
+ image = Image.open(image).convert('RGB')
22
+ else:
23
+ # If image is a NumPy array, convert it to a PIL image
24
+ image = Image.fromarray(image.astype('uint8'), 'RGB')
25
+ # Apply the same transformations as before
26
+ image = transform(image).unsqueeze(0)
27
+ return image.to(device)
28
+
29
 
30
  #Defining the predict function
31
  def style_transfer(cont_img,styl_img):