-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathupscale_image.py
More file actions
46 lines (33 loc) · 1.24 KB
/
upscale_image.py
File metadata and controls
46 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
{filename}
==============================================================================
| Example of how to upscale an image
|
| It expects an image "results/image.png" to exist and will generate the resulting masks in this same folder
| The image should be 512x768 by default, modify :code:`image_size` to change it
"""
import asyncio
import base64
import time
from pathlib import Path
from example.boilerplate import API
from novelai_api.NovelAIError import NovelAIError
async def main():
d = Path("results")
d.mkdir(exist_ok=True)
image_size = (512, 768)
async with API() as api_handler:
api = api_handler.api
image = base64.b64encode((d / "image.png").read_bytes()).decode()
# disable the type check on scale in _low_level.py to check on float values
for scale in (2, 4):
try:
_, img = await api.low_level.upscale_image(image, *image_size, scale)
(d / f"image_upscaled_{scale}.png").write_bytes(img)
print(f"Generated upscale {scale}")
time.sleep(2)
except NovelAIError as e:
print(f"Failed upscale {scale}: {e}")
time.sleep(5)
if __name__ == "__main__":
asyncio.run(main())