Testys commited on
Commit
1a5b9a6
1 Parent(s): 0f0dee3

Update utils/image_utils.py

Browse files
Files changed (1) hide show
  1. utils/image_utils.py +8 -3
utils/image_utils.py CHANGED
@@ -3,6 +3,9 @@ from PIL import Image
3
  import urllib.parse as parse
4
  import os
5
 
 
 
 
6
 
7
  # Verify url
8
  def check_url(string):
@@ -14,8 +17,10 @@ def check_url(string):
14
 
15
 
16
  # Load an image
17
- def load_image(image_path):
18
- if check_url(image_path):
19
- return Image.open(requests.get(image_path="https://images.unsplash.com/photo-1532635236-d50c8592eb08?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1411&q=80", stream=True).raw)
20
  elif os.path.exists(image_path):
21
  return Image.open(image_path.read())
 
 
 
3
  import urllib.parse as parse
4
  import os
5
 
6
+ DEFAULT_URL = "https://images.unsplash.com/photo-1532635236-d50c8592eb08?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1411&q=80"
7
+
8
+
9
 
10
  # Verify url
11
  def check_url(string):
 
17
 
18
 
19
  # Load an image
20
+ def load_image(image_path=None):
21
+ if image_path and check_url(image_path):
22
+ return Image.open(requests.get(image_path, stream=True).raw)
23
  elif os.path.exists(image_path):
24
  return Image.open(image_path.read())
25
+ else:
26
+ return Image.open(requests.get(DEFAULT_URL, stream=True).raw)