random-image 0.0.1__py3-none-any.whl
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/__init__.py +1 -0
- random_image/exceptions/__init__.py +0 -0
- random_image/functions/__init__.py +0 -0
- random_image/random_image.py +65 -0
- random_image/repository/car.yaml +15 -0
- random_image/repository/dog.yaml +6 -0
- random_image/repository/rabbit.yaml +15 -0
- random_image-0.0.1.dist-info/METADATA +22 -0
- random_image-0.0.1.dist-info/RECORD +11 -0
- random_image-0.0.1.dist-info/WHEEL +5 -0
- random_image-0.0.1.dist-info/top_level.txt +1 -0
random_image/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .random_image import random_image
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
- https://images.unsplash.com/photo-1580273916550-e323be2ae537
|
|
2
|
+
- https://images.unsplash.com/photo-1503376780353-7e6692767b70
|
|
3
|
+
- https://images.unsplash.com/photo-1765211003784-a82564cb8d3d
|
|
4
|
+
- https://images.unsplash.com/photo-1542362567-b07e54358753?
|
|
5
|
+
- https://images.unsplash.com/photo-1568605117036-5fe5e7bab0b7
|
|
6
|
+
- https://images.unsplash.com/photo-1492144534655-ae79c964c9d7
|
|
7
|
+
- https://images.unsplash.com/photo-1494976388531-d1058494cdd8
|
|
8
|
+
- https://images.unsplash.com/photo-1779184638442-fcbd65b0437a
|
|
9
|
+
- https://images.unsplash.com/photo-1567808291548-fc3ee04dbcf0
|
|
10
|
+
- https://images.unsplash.com/photo-1542282088-fe8426682b8f
|
|
11
|
+
- https://images.unsplash.com/photo-1511919884226-fd3cad34687c
|
|
12
|
+
- https://images.unsplash.com/photo-1533473359331-0135ef1b58bf
|
|
13
|
+
- https://images.unsplash.com/photo-1771962033103-da4ef275b9c0
|
|
14
|
+
- https://images.unsplash.com/photo-1502877338535-766e1452684a
|
|
15
|
+
- https://images.unsplash.com/photo-1583121274602-3e2820c69888
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
- https://images.unsplash.com/photo-1530281700549-e82e7bf110d6
|
|
2
|
+
- https://images.unsplash.com/photo-1552053831-71594a27632d
|
|
3
|
+
- https://images.unsplash.com/photo-1783936093098-2daf9e8ef72e
|
|
4
|
+
- https://images.unsplash.com/photo-1763718205007-fb085a276026
|
|
5
|
+
- https://images.unsplash.com/photo-1534361960057-19889db9621e
|
|
6
|
+
- https://images.unsplash.com/photo-1596492784531-6e6eb5ea9993
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
- https://images.unsplash.com/photo-1585110396000-c9ffd4e4b308
|
|
2
|
+
- https://images.unsplash.com/photo-1609151354448-c4a53450c6e9
|
|
3
|
+
- https://images.unsplash.com/photo-1777060971398-d1c72a00932a
|
|
4
|
+
- https://images.unsplash.com/photo-1591561582301-7ce6588cc286
|
|
5
|
+
- https://images.unsplash.com/photo-1782529913535-10c9427a0bb1
|
|
6
|
+
- https://images.unsplash.com/photo-1535241749838-299277b6305f
|
|
7
|
+
- https://images.unsplash.com/photo-1425082661705-1834bfd09dca
|
|
8
|
+
- https://images.unsplash.com/photo-1452857297128-d9c29adba80b
|
|
9
|
+
- https://images.unsplash.com/photo-1782419703784-d9c58fdefb0f
|
|
10
|
+
- https://images.unsplash.com/photo-1623686070581-5d2eb8187fc2
|
|
11
|
+
- https://images.unsplash.com/photo-1581872454565-822dac9367aa
|
|
12
|
+
- https://images.unsplash.com/photo-1481500576737-9238440343a6
|
|
13
|
+
- https://images.unsplash.com/photo-1779272005978-89b72b340a1d
|
|
14
|
+
- https://images.unsplash.com/photo-1589952283406-b53a7d1347e8
|
|
15
|
+
- https://images.unsplash.com/photo-1591382386627-349b692688ff
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: random_image
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Get a random image in Python.
|
|
5
|
+
Author-email: Taha Shieenavaz <tahashieenavaz@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/tahashieenavaz/random-image
|
|
7
|
+
Project-URL: Repository, https://github.com/tahashieenavaz/random-image
|
|
8
|
+
Project-URL: Documentation, https://github.com/tahashieenavaz/random-image#readme
|
|
9
|
+
Keywords: image,python,productivity
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: pillow
|
|
19
|
+
Requires-Dist: pyyaml
|
|
20
|
+
|
|
21
|
+
# random-image
|
|
22
|
+
Get a random image instantly.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
random_image/__init__.py,sha256=BOqzgb1ZQV_newmcCptYzKqTMgmVddDtYt0gUBUQySc,39
|
|
2
|
+
random_image/random_image.py,sha256=DdyJMLg7iG3A0heb7fNyK4xqWKFCIv6Cx7Qo7uydLtk,1545
|
|
3
|
+
random_image/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
random_image/functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
random_image/repository/car.yaml,sha256=icfsXzE19O68Ey5M__e0I_wt4doz0iw9kgGYC3Yp8o4,940
|
|
6
|
+
random_image/repository/dog.yaml,sha256=OwgqsNDIUXmPDUbqFw8i2dB0skM-to__RyhyHz8Br7E,374
|
|
7
|
+
random_image/repository/rabbit.yaml,sha256=xC6yO3XkO8tT6cQccMHKRvDKHNrAgk4k5A9UgNV8Bi8,944
|
|
8
|
+
random_image-0.0.1.dist-info/METADATA,sha256=MltmRrGl2AmJNFvl3TrAruj78cOQSpix_5_mlt33Fek,871
|
|
9
|
+
random_image-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
10
|
+
random_image-0.0.1.dist-info/top_level.txt,sha256=OcTKlpv2JY4W70_8NKVQuSOsq7akQwtpzWru0ZMEPeY,13
|
|
11
|
+
random_image-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
random_image
|