Skip to main content

NovelAI Python Binding With Pydantic

Project description

banner


PyPI version Downloads

✨ 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 🙏

BackEnd

novelai-api

NovelAI-API

Project details


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.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

novelai_python-0.4.1-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file novelai_python-0.4.1.tar.gz.

File metadata

  • Download URL: novelai_python-0.4.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.12.4 CPython/3.10.12

File hashes

Hashes for novelai_python-0.4.1.tar.gz
Algorithm Hash digest
SHA256 3461d885b68b0c2018e6d6a27be2e32e756e4f151d511bb234c9404c6e08fe3e
MD5 fea7eca2d6355e3394b49d00b5172e36
BLAKE2b-256 e4716126865a762d7afbbc6af2acfabf48fb3af254bd907fac09615e73d95711

See more details on using hashes here.

File details

Details for the file novelai_python-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: novelai_python-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.12.4 CPython/3.10.12

File hashes

Hashes for novelai_python-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e25a1a3efd2395a47505371edf4d5477bc3e4473fac97a273b8f8f2e5eeccb16
MD5 5c923d9706227fc23679cf49f6083a99
BLAKE2b-256 a85a46412d5e8b9864b2d7cce465356895533eee3d50b8a4debde1e5a017bd2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page