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.
Files changed (27) hide show
  1. {random_image-0.0.1 → random_image-0.0.2}/PKG-INFO +1 -1
  2. random_image-0.0.2/src/random_image/functions/__init__.py +5 -0
  3. random_image-0.0.2/src/random_image/functions/image_urls.py +14 -0
  4. random_image-0.0.2/src/random_image/functions/list_categories.py +8 -0
  5. random_image-0.0.2/src/random_image/functions/process_category.py +9 -0
  6. random_image-0.0.2/src/random_image/functions/random_image_url.py +6 -0
  7. random_image-0.0.2/src/random_image/functions/repository_path.py +11 -0
  8. random_image-0.0.2/src/random_image/random_image.py +32 -0
  9. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/PKG-INFO +1 -1
  10. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/SOURCES.txt +5 -0
  11. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/scm_file_list.json +5 -0
  12. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/scm_version.json +2 -2
  13. random_image-0.0.1/src/random_image/functions/__init__.py +0 -0
  14. random_image-0.0.1/src/random_image/random_image.py +0 -65
  15. {random_image-0.0.1 → random_image-0.0.2}/.github/workflows/publish.yaml +0 -0
  16. {random_image-0.0.1 → random_image-0.0.2}/.gitignore +0 -0
  17. {random_image-0.0.1 → random_image-0.0.2}/README.md +0 -0
  18. {random_image-0.0.1 → random_image-0.0.2}/pyproject.toml +0 -0
  19. {random_image-0.0.1 → random_image-0.0.2}/setup.cfg +0 -0
  20. {random_image-0.0.1 → random_image-0.0.2}/src/random_image/__init__.py +0 -0
  21. {random_image-0.0.1 → random_image-0.0.2}/src/random_image/exceptions/__init__.py +0 -0
  22. {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/car.yaml +0 -0
  23. {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/dog.yaml +0 -0
  24. {random_image-0.0.1 → random_image-0.0.2}/src/random_image/repository/rabbit.yaml +0 -0
  25. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/dependency_links.txt +0 -0
  26. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/requires.txt +0 -0
  27. {random_image-0.0.1 → random_image-0.0.2}/src/random_image.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: random_image
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Get a random image in Python.
5
5
  Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/tahashieenavaz/random-image
@@ -0,0 +1,5 @@
1
+ from .repository_path import repository_path
2
+ from .list_categories import list_categories
3
+ from .process_category import process_category
4
+ from .image_urls import image_urls
5
+ from .random_image_url import random_image_url
@@ -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,8 @@
1
+ from functools import cache
2
+ from .repository_path import repository_path
3
+
4
+
5
+ @cache
6
+ def list_categories():
7
+ yaml_files_generator = repository_path(glob="*.yaml")
8
+ return list(map(lambda x: x.name.replace(".yaml", ""), yaml_files_generator))
@@ -0,0 +1,9 @@
1
+ import random
2
+ from typing import Optional
3
+ from .list_categories import list_categories
4
+
5
+
6
+ def process_category(category: Optional[str] = None):
7
+ if category is not None:
8
+ return category
9
+ return random.choice(list_categories())
@@ -0,0 +1,6 @@
1
+ import random
2
+ from .image_urls import image_urls
3
+
4
+
5
+ def random_image_url(category: str):
6
+ return random.choice(image_urls(category))
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: random_image
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Get a random image in Python.
5
5
  Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/tahashieenavaz/random-image
@@ -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",
@@ -1,7 +1,7 @@
1
1
  {
2
- "tag": "0.0.1",
2
+ "tag": "0.0.2",
3
3
  "distance": 0,
4
- "node": "gca79dbf54536d89535d7c45b24f2b1b2df23deab",
4
+ "node": "g85804743a714e5dc94c8a33801db054d914c4537",
5
5
  "dirty": false,
6
6
  "branch": "HEAD",
7
7
  "node_date": "2026-11-29"
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