NovelAI Python Binding With Pydantic
Project description
✨ NovelAI api python sdk with Pydantic.
The goal of this repository is to use Pydantic to build legitimate requests to access the NovelAI API service.
Roadmap 🚧
- tool.random_prompt
- tool.paint_mask
- tool.image_metadata
- /ai/generate-image
- /user/subscription
- /user/login
- /user/information
- /ai/upscale
- /ai/generate-image/suggest-tags
- /ai/generate-voice
- /ai/annotate-image
- /ai/classify
- /ai/generate-prompt
- /ai/generate
GenerateImageInfer.calculate_cost is correct in most cases, but please request account information to get accurate consumption information.
This repo is maintained by me personally now. If you have any questions, please feel free to open an issue.
Usage 🖥️
pip install novelai-python
More examples can be found in the playground directory, read code as documentation.
import asyncio
import os
from dotenv import load_dotenv
from pydantic import SecretStr
from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential, LoginCredential, ApiCredential
load_dotenv()
enhance = "year 2023,dynamic angle, best quality, amazing quality, very aesthetic, absurdres"
async def main():
globe_s = JwtCredential(
jwt_token=SecretStr(os.getenv("NOVELAI_JWT")) # ey****
)
globe_s1 = ApiCredential(
api_token=SecretStr(os.getenv("NOVELAI_JWT")) # pst-***
)
globe_s2 = LoginCredential(
username=os.getenv("NOVELAI_USERNAME"),
password=SecretStr(os.getenv("NOVELAI_PASSWORD"))
)
gen = await GenerateImageInfer.build(
prompt=f"1girl,{enhance}")
cost = gen.calculate_cost(is_opus=True)
print(f"charge: {cost} if you are vip3")
resp = gen.request(session=globe_s)
resp: ImageGenerateResp
print(resp.meta)
file = resp.files[0]
with open(file[0], "wb") as f:
f.write(file[1])
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Random Prompt
from novelai_python.tool.random_prompt import RandomPromptGenerator
s = RandomPromptGenerator(nsfw_enabled=False).random_prompt()
print(s)
Run A Server
pip install novelai_python
python3 -m novelai_python.server -h '127.0.0.1' -p 7888
Acknowledgements 🙏
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
novelai_python-0.4.6.tar.gz
(1.0 MB
view hashes)
Built Distribution
Close
Hashes for novelai_python-0.4.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 890f7ce2a2621fb330bcdb3e22b4de24380487d165099ab2a75e76aa8f6c008f |
|
MD5 | 12f9942ecaee8e3fae2ce0973173c022 |
|
BLAKE2b-256 | cc1e41626155838fdb92553fa968e8128e7b92b5da92003167ffd298fa9c29f9 |