from urllib import request
from io import BytesIO


def download_image(url: str):
    """Pass an url to download image for prediction

    Params
    ------
    url: str
        Url from which to retrieve image

    Returns
    ------
    filename: str
        By default every downloaded image will be stored
        in the current directory as downloaded_image.jpg
    """

    # Lazy import urrlib
    # import urllib

    # url, filename = (url, "downloaded_image.jpg")

    # try:
    #    urllib.URLopener().retrieve(url, filename)
    # except:
    #    urllib.request.urlretrieve(url, filename)

    # return filename


    with request.urlopen(url) as resp:
        buffer = resp.read()

    image_stream = BytesIO(buffer)

    return image_stream