Spaces:
Runtime error
Runtime error
File size: 582 Bytes
67d6f5b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import requests
from PIL import Image
import urllib.parse as parse
import os
class UrlTest:
def check_url(self, url_string):
try:
result = parse.urlparse(url_string)
return all([result.scheme, result.netloc, result.path])
except:
return url_string
# Load an image
def load_image(self, image_path):
if self.check_url(image_path):
return Image.open(requests.get(image_path, stream=True).raw)
elif os.path.exists(image_path):
return Image.open(image_path)
|