random-image 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {random_image-0.0.1 → random_image-0.0.2}/PKG-INFO +1 -1
- random_image-0.0.2/src/random_image/functions/__init__.py +5 -0
- random_image-0.0.2/src/random_image/functions/image_urls.py +14 -0
- random_image-0.0.2/src/random_image/functions/list_categories.py +8 -0
- random_image-0.0.2/src/random_image/functions/process_category.py +9 -0
- random_image-0.0.2/src/random_image/functions/random_image_url.py +6 -0
- random_image-0.0.2/src/random_image/functions/repository_path.py +11 -0
- random_image-0.0.2/src/random_image/random_image.py +32 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/PKG-INFO +1 -1
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/SOURCES.txt +5 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/scm_file_list.json +5 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/scm_version.json +2 -2
- random_image-0.0.1/src/random_image/functions/__init__.py +0 -0
- random_image-0.0.1/src/random_image/random_image.py +0 -65
- {random_image-0.0.1 → random_image-0.0.2}/.github/workflows/publish.yaml +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/.gitignore +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/README.md +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/pyproject.toml +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/setup.cfg +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image/__init__.py +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image/exceptions/__init__.py +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/car.yaml +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/dog.yaml +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/rabbit.yaml +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/dependency_links.txt +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/requires.txt +0 -0
- {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import yaml
|
|
3
|
+
from functools import cache
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@cache
|
|
7
|
+
def image_urls(category: str):
|
|
8
|
+
with (
|
|
9
|
+
importlib.resources.files("random_image")
|
|
10
|
+
.joinpath(f"repository/{category}.yaml")
|
|
11
|
+
.open() as stream
|
|
12
|
+
):
|
|
13
|
+
image_urls = yaml.safe_load(stream=stream)
|
|
14
|
+
return image_urls
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
from functools import cache
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@cache
|
|
7
|
+
def repository_path(glob: Optional[str] = None):
|
|
8
|
+
base_path = importlib.resources.files("random_image").joinpath(f"repository")
|
|
9
|
+
if glob is not None:
|
|
10
|
+
return base_path.glob(glob)
|
|
11
|
+
return base_path
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
from PIL import Image
|
|
5
|
+
from random_image.functions import random_image_url
|
|
6
|
+
from random_image.functions import process_category
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def random_image(
|
|
10
|
+
category: Optional[str] = None,
|
|
11
|
+
as_numpy: bool = False,
|
|
12
|
+
as_tensor: bool = False,
|
|
13
|
+
width: int = 300,
|
|
14
|
+
height: int = 300,
|
|
15
|
+
):
|
|
16
|
+
category = process_category(category)
|
|
17
|
+
image_url = random_image_url(category)
|
|
18
|
+
response = requests.get(image_url)
|
|
19
|
+
response.raise_for_status()
|
|
20
|
+
pil = Image.open(BytesIO(response.content)).resize((width, height))
|
|
21
|
+
|
|
22
|
+
if as_numpy:
|
|
23
|
+
import numpy
|
|
24
|
+
|
|
25
|
+
return numpy.asarray(pil)
|
|
26
|
+
|
|
27
|
+
if as_tensor:
|
|
28
|
+
import torch
|
|
29
|
+
|
|
30
|
+
return torch.from_numpy(numpy.asarray(pil))
|
|
31
|
+
|
|
32
|
+
return pil
|
|
@@ -13,6 +13,11 @@ src/random_image.egg-info/scm_version.json
|
|
|
13
13
|
src/random_image.egg-info/top_level.txt
|
|
14
14
|
src/random_image/exceptions/__init__.py
|
|
15
15
|
src/random_image/functions/__init__.py
|
|
16
|
+
src/random_image/functions/image_urls.py
|
|
17
|
+
src/random_image/functions/list_categories.py
|
|
18
|
+
src/random_image/functions/process_category.py
|
|
19
|
+
src/random_image/functions/random_image_url.py
|
|
20
|
+
src/random_image/functions/repository_path.py
|
|
16
21
|
src/random_image/repository/car.yaml
|
|
17
22
|
src/random_image/repository/dog.yaml
|
|
18
23
|
src/random_image/repository/rabbit.yaml
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
"src/random_image/__init__.py",
|
|
8
8
|
"src/random_image/exceptions/__init__.py",
|
|
9
9
|
"src/random_image/functions/__init__.py",
|
|
10
|
+
"src/random_image/functions/image_urls.py",
|
|
11
|
+
"src/random_image/functions/list_categories.py",
|
|
12
|
+
"src/random_image/functions/process_category.py",
|
|
13
|
+
"src/random_image/functions/random_image_url.py",
|
|
14
|
+
"src/random_image/functions/repository_path.py",
|
|
10
15
|
"src/random_image/random_image.py",
|
|
11
16
|
"src/random_image/repository/car.yaml",
|
|
12
17
|
"src/random_image/repository/dog.yaml",
|
|
File without changes
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import random
|
|
2
|
-
import importlib
|
|
3
|
-
import yaml
|
|
4
|
-
import requests
|
|
5
|
-
from typing import Optional
|
|
6
|
-
from functools import cache
|
|
7
|
-
from io import BytesIO
|
|
8
|
-
from PIL import Image
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@cache
|
|
12
|
-
def repository_path(glob: Optional[str] = None):
|
|
13
|
-
base_path = importlib.resources.files("random_image").joinpath(f"repository")
|
|
14
|
-
if glob is not None:
|
|
15
|
-
return base_path.glob(glob)
|
|
16
|
-
return base_path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@cache
|
|
20
|
-
def list_categories():
|
|
21
|
-
yaml_files_generator = repository_path(glob="*.yaml")
|
|
22
|
-
return list(map(lambda x: x.name.replace(".yaml", ""), yaml_files_generator))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def process_category(category: Optional[str] = None):
|
|
26
|
-
if category is not None:
|
|
27
|
-
return category
|
|
28
|
-
return random.choice(list_categories())
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@cache
|
|
32
|
-
def image_urls(category: str):
|
|
33
|
-
with (
|
|
34
|
-
importlib.resources.files("random_image")
|
|
35
|
-
.joinpath(f"repository/{category}.yaml")
|
|
36
|
-
.open() as stream
|
|
37
|
-
):
|
|
38
|
-
image_urls = yaml.safe_load(stream=stream)
|
|
39
|
-
return image_urls
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def random_image_url(category: str):
|
|
43
|
-
return random.choice(image_urls(category))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def random_image(
|
|
47
|
-
category: Optional[str] = None, as_numpy: bool = False, as_tensor: bool = False
|
|
48
|
-
):
|
|
49
|
-
category = process_category(category)
|
|
50
|
-
image_url = random_image_url(category)
|
|
51
|
-
response = requests.get(image_url)
|
|
52
|
-
response.raise_for_status()
|
|
53
|
-
pil = Image.open(BytesIO(response.content))
|
|
54
|
-
|
|
55
|
-
if as_numpy:
|
|
56
|
-
import numpy
|
|
57
|
-
|
|
58
|
-
return numpy.array(pil)
|
|
59
|
-
|
|
60
|
-
if as_tensor:
|
|
61
|
-
import torchvision
|
|
62
|
-
|
|
63
|
-
return torchvision.io.read_image(pil)
|
|
64
|
-
|
|
65
|
-
return pil
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|