✨ 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/annotate-image
- /ai/classify
- /ai/generate-prompt
- /ai/generate
- /ai/generate-voice
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 '0.0.0.0' -p 7888
Acknowledgements 🙏
Metadata
Release files for novelai-python 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| novelai_python-0.4.0.tar.gz | 1.0 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| novelai_python-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / novelai_python-0.4.0.tar.gz
| Download URL | novelai_python-0.4.0.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4615fd3e0dc28a2308f15a8ccd77d1100d8f4b03bba163bcab4b3b63bdc35e71
|
|
BLAKE2b-256 checksum How to use checksums |
26d0dec43b5ca333c48de5b3866225e65622b0e8ee56f1d4e121ec196de8fa27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.12.4 CPython/3.10.12
|
Release files / novelai_python-0.4.0-py3-none-any.whl
| Download URL | novelai_python-0.4.0-py3-none-any.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bab88df5668c84020c9fd328c9e2fccbc6c4259950ab6a21a89d189f0a525efe
|
|
BLAKE2b-256 checksum How to use checksums |
73a96a9cef31404726bc39af96ae50ff972008ad5801126c4fc24f51e0d20c0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.12.4 CPython/3.10.12
|