Skip to content

Commit 96e4b13

Browse files
committedJun 26, 2023
2.0
Movign to latest og, and full transfer to httpx.
1 parent 7c1005f commit 96e4b13

10 files changed

+976
-530
lines changed
 

‎app.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
from imaginepy import Imagine, Style, Ratio
1+
from imaginepy import Imagine
2+
from imaginepy.constants import *
23

34

45
def main():
5-
imagine = Imagine(style=Style.ANIME_V2) #initialize with style
6+
imagine = Imagine()
67

78
img_data = imagine.sdprem(
89
prompt="Woman sitting on a table, looking at the sky, seen from behind",
9-
style=Style.ANIME_V2,
10-
ratio=Ratio.RATIO_16X9
10+
style=Style.NO_STYLE,
11+
ratio=Ratio.RATIO_16X9,
12+
negative="",
13+
seed=1000,
14+
cfg=16,
15+
model=Model.REALISTIC,
16+
asbase64=False # default is false, putting it here as presentation.
1117
)
1218

1319
if img_data is None:
1420
print("An error occurred while generating the image.")
1521
return
1622

17-
img_data = imagine.upscale(image=img_data)
23+
img_data = imagine.upscale(img_data)
1824

1925
if img_data is None:
2026
print("An error occurred while upscaling the image.")
2127
return
2228

2329
try:
24-
with open("example.png", mode="wb") as img_file:
30+
with open("example.jpeg", mode="wb") as img_file:
2531
img_file.write(img_data)
2632
except Exception as e:
2733
print(f"An error occurred while writing the image to file: {e}")

‎app_async.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import asyncio
2-
from imaginepy import AsyncImagine, Style, Ratio
2+
from imaginepy import AsyncImagine
3+
from imaginepy.constants import *
34

45

56
async def main():
6-
imagine = AsyncImagine(style=Style.ANIME_V2) #initialize with style
7-
8-
img_data = await imagine.sdprem(
7+
imagine = AsyncImagine()
8+
img_data = imagine.sdprem(
99
prompt="Woman sitting on a table, looking at the sky, seen from behind",
10-
style=Style.ANIME_V2,
11-
ratio=Ratio.RATIO_16X9
10+
style=Style.NO_STYLE,
11+
ratio=Ratio.RATIO_16X9,
12+
negative="",
13+
seed=1000,
14+
cfg=16,
15+
model=Model.REALISTIC,
16+
asbase64=False # default is false, putting it here as presentation.
1217
)
1318

1419
if img_data is None:
@@ -26,9 +31,8 @@ async def main():
2631
img_file.write(img_data)
2732
except Exception as e:
2833
print(f"An error occurred while writing the image to file: {e}")
29-
34+
3035
await imagine.close()
31-
3236

3337

3438
if __name__ == "__main__":

‎example.jpeg

2.94 MB
Loading

‎imaginepy/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .sync_imagine import Imagine
2-
from .async_imagine import AsyncImagine
1+
from .sync_imagine import Imagine, DeviantArt
2+
from .async_imagine import AsyncImagine, DeviantArt
33
from .constants import *
44

5-
__version__ = "1.1.0"
5+
__version__ = "2.0.0"

‎imaginepy/async_imagine.py

+276-158
Large diffs are not rendered by default.

‎imaginepy/constants.py

+311-184
Large diffs are not rendered by default.

‎imaginepy/exceptions.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class ImaginePyException(Exception):
2+
"""Exceptions used by pyimagine."""
3+
4+
5+
class InvalidWord(ImaginePyException):
6+
"""Used word is invalid."""
7+
8+
9+
class InvalidSize(ImaginePyException):
10+
"""Both sizes must be the same."""
11+
12+
13+
class BannedContent(ImaginePyException):
14+
"""Content wanting to be generated is banned."""

‎imaginepy/sync_imagine.py

+270-163
Large diffs are not rendered by default.

‎imaginepy/utils.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import random
2+
from io import BytesIO
3+
4+
from PIL import Image
5+
6+
7+
def bytes2png(content: bytes) -> bytes:
8+
# Convert the image to PNG format
9+
src_image = Image.open(BytesIO(content))
10+
png_image = src_image.convert("RGBA")
11+
12+
# Save the PNG image to bytes
13+
png_data = BytesIO()
14+
png_image.save(png_data, format="PNG")
15+
png_data.seek(0)
16+
return png_data.getvalue()
17+
18+
19+
def clear_dict(value: dict) -> dict:
20+
return {key: value for key, value in value.items() if value is not None} if value else None
21+
22+
23+
def get_cfg(value: float) -> float:
24+
if value < 0.0 or value > 16.0:
25+
raise ValueError(f"Invalid CFG, must be in range (0; 16), {value}")
26+
return value
27+
28+
29+
def get_steps(value: int) -> int:
30+
if value < 0 or value > 50:
31+
raise ValueError(f"Invalid steps, must be in range (0; 50), {value}")
32+
return value
33+
34+
35+
def get_word(value: str) -> str:
36+
chars = list(value.lower())
37+
size = len(chars) - 1
38+
vowel = chars[0] in "aeiouy"
39+
40+
for i in range(size + 1):
41+
if i > 0 and chars[i] == chars[i - 1]:
42+
chars.insert(i + 1, chars[i])
43+
return "".join(chars)
44+
if i == size // 2 and size % 2 == 1:
45+
chars.insert(i + 1, chars[i])
46+
return "".join(chars)
47+
48+
if vowel:
49+
chars.insert(2, chars[1])
50+
else:
51+
i = random.randint(0, size)
52+
chars.insert(i + 1, chars[i])
53+
return "".join(chars)
54+
55+
56+
def same_size(src1: bytes, src2: bytes) -> bool:
57+
width1, height1 = Image.open(BytesIO(src1)).size
58+
width2, height2 = Image.open(BytesIO(src2)).size
59+
return width1 == width2 and height1 == height2

‎setup.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,39 @@
55

66
setup(
77
name='imaginepy',
8-
version='1.1.0',
8+
version='2.0.0',
99
author='CEED',
1010
author_email='',
1111
description='Python library to create Art with AI.',
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
url='https://github.com/ItsCEED/imaginepy',
15+
license="GPL-3.0-only",
1516
packages=find_packages(),
17+
keywords=[
18+
"art",
19+
"image",
20+
"ai",
21+
"stable-diffusion"
22+
],
1623
classifiers=[
17-
"Environment :: Console",
18-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
24+
"Development Status :: 5 - Production/Stable",
25+
"Intended Audience :: Developers",
26+
"Intended Audience :: End Users/Desktop",
27+
"Natural Language :: English",
1928
"Operating System :: OS Independent",
20-
"Programming Language :: Python :: 3.4",
21-
"Programming Language :: Python :: 3.5",
22-
"Programming Language :: Python :: 3.6",
29+
"Programming Language :: Python :: 3",
2330
"Programming Language :: Python :: 3.7",
31+
"Programming Language :: Python :: 3.8",
32+
"Programming Language :: Python :: 3.9",
33+
"Programming Language :: Python :: 3.10",
2434
"Topic :: Utilities"
2535
],
2636
python_requires='>=3.7',
2737
install_requires=[
28-
'requests',
38+
'aiohttp',
2939
'requests_toolbelt',
3040
'langdetect',
41+
'pybase64'
3142
],
32-
)
43+
)

0 commit comments

Comments
 (0)
Please sign in to comment.