-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgenerate_image_with_inpainting.py
More file actions
40 lines (28 loc) · 1.08 KB
/
generate_image_with_inpainting.py
File metadata and controls
40 lines (28 loc) · 1.08 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
"""
{filename}
==============================================================================
| Example of how to generate an image with inpainting
|
| The resulting image will be placed in a folder named "results"
"""
import asyncio
import base64
from pathlib import Path
from example.boilerplate import API
from novelai_api.ImagePreset import ImageGenerationType, ImageModel, ImagePreset
async def main():
d = Path("results")
d.mkdir(exist_ok=True)
async with API() as api_handler:
api = api_handler.api
image = base64.b64encode((d / "image.png").read_bytes()).decode()
mask = base64.b64encode((d / "inpainting_mask.png").read_bytes()).decode()
model = ImageModel.Inpainting_Anime_Full
preset = ImagePreset.from_default_config(model)
preset.image = image
preset.mask = mask
preset.seed = 42
async for _, img in api.high_level.generate_image("1girl", model, preset, ImageGenerationType.INPAINTING):
(d / "image_with_inpainting.png").write_bytes(img)
if __name__ == "__main__":
asyncio.run(main())