-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Add inpainting and /ai/generate-prompt
No idea what this new endpoint is for
- Loading branch information
Showing
6 changed files
with
127 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
{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() | ||
|
||
preset = ImagePreset() | ||
preset.noise = 0.1 | ||
# note that steps = 28, not 50, which mean strength needs to be adjusted accordingly | ||
preset.strength = 0.5 | ||
preset.image = image | ||
preset.mask = mask | ||
preset.add_original_image = False | ||
preset.seed = 42 | ||
|
||
async for _, img in api.high_level.generate_image( | ||
"1girl", ImageModel.Inpainting_Anime_Full, preset, ImageGenerationType.INPAINTING | ||
): | ||
(d / "image_with_inpainting.png").write_bytes(img) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters