Skip to content

Commit

Permalink
✨ feat(playground): update Login to LoginCredential in generate.py, g…
Browse files Browse the repository at this point in the history
…enerate_stream.py, generate_image_img2img.py, vibe_img2img.py, generate_image.py

Updated the usage of Login to LoginCredential in multiple files for consistency.
  • Loading branch information
sudoskys committed Apr 10, 2024
1 parent bc54200 commit 1f8a9ac
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ loop.run_until_complete(main())
```python
import asyncio
import os
from pydantic import SecretStr

from dotenv import load_dotenv
from pydantic import SecretStr

from novelai_python import APIError, LoginCredential
from novelai_python.sdk.ai.generate import TextLLMModel, LLM
Expand Down
8 changes: 4 additions & 4 deletions playground/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from loguru import logger
from pydantic import SecretStr

from novelai_python import APIError, Login
from novelai_python import APIError, LoginCredential
from novelai_python import JwtCredential
from novelai_python.sdk.ai.generate import TextLLMModel, LLM

Expand All @@ -18,9 +18,9 @@

async def chat(prompt="Hello"):
"""Or you can use the login credential to get the renewable jwt token"""
_login_credential = Login.build(
user_name=os.getenv("NOVELAI_USER"),
password=os.getenv("NOVELAI_PASS")
_login_credential = LoginCredential(
username=os.getenv("NOVELAI_USER"),
password=SecretStr(os.getenv("NOVELAI_PASS"))
)
# await _login_credential.request()
# print(f"Model List:{enum_to_list(TextLLMModel)}")
Expand Down
9 changes: 5 additions & 4 deletions playground/generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import asyncio
import os
import pathlib

from dotenv import load_dotenv
from pydantic import SecretStr

from novelai_python import APIError, Login
from novelai_python import APIError, LoginCredential
from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential
from novelai_python.sdk.ai.generate_image import Action, Sampler, Model
from novelai_python.utils.useful import enum_to_list
Expand All @@ -21,9 +22,9 @@ async def generate(prompt="1girl, year 2023, dynamic angle, best quality, amazin
raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it")
credential = JwtCredential(jwt_token=SecretStr(jwt))
"""Or you can use the login credential to get the renewable jwt token"""
_login_credential = Login.build(
user_name=os.getenv("NOVELAI_USER"),
password=os.getenv("NOVELAI_PASS")
_login_credential = LoginCredential(
username=os.getenv("NOVELAI_USER"),
password=SecretStr(os.getenv("NOVELAI_PASS"))
)
# await _login_credential.request()
print(f"Action List:{enum_to_list(Action)}")
Expand Down
8 changes: 4 additions & 4 deletions playground/generate_image_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from loguru import logger
from pydantic import SecretStr

from novelai_python import APIError, Login
from novelai_python import APIError, Login, LoginCredential
from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential
from novelai_python.sdk.ai.generate_image import Action, Sampler
from novelai_python.utils.useful import enum_to_list
Expand All @@ -26,9 +26,9 @@ async def generate(
raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it")
credential = JwtCredential(jwt_token=SecretStr(jwt))
"""Or you can use the login credential to get the jwt token"""
_login_credential = Login.build(
user_name=os.getenv("NOVELAI_USER"),
password=os.getenv("NOVELAI_PASS")
_login_credential = LoginCredential(
username=os.getenv("NOVELAI_USER"),
password=SecretStr(os.getenv("NOVELAI_PASS"))
)
# await _login_credential.request()
print(f"Action List:{enum_to_list(Action)}")
Expand Down
8 changes: 4 additions & 4 deletions playground/generate_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from loguru import logger
from pydantic import SecretStr

from novelai_python import APIError, Login
from novelai_python import APIError, Login, LoginCredential
from novelai_python import JwtCredential
from novelai_python.sdk.ai.generate_stream import TextLLMModel, LLMStream, LLMStreamResp

Expand All @@ -25,9 +25,9 @@ def loop_connect(resp: list):

async def stream(prompt="Hello"):
"""Or you can use the login credential to get the renewable jwt token"""
_login_credential = Login.build(
user_name=os.getenv("NOVELAI_USER"),
password=os.getenv("NOVELAI_PASS")
_login_credential = LoginCredential(
username=os.getenv("NOVELAI_USER"),
password=SecretStr(os.getenv("NOVELAI_PASS"))
)
# await _login_credential.request()
# print(f"Model List:{enum_to_list(TextLLMModel)}")
Expand Down
9 changes: 5 additions & 4 deletions playground/vibe_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import asyncio
import os
import pathlib

from dotenv import load_dotenv
from pydantic import SecretStr

from novelai_python import APIError, Login
from novelai_python import APIError, LoginCredential
from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential
from novelai_python.sdk.ai.generate_image import Action, Sampler
from novelai_python.utils.useful import enum_to_list
Expand All @@ -21,9 +22,9 @@ async def generate(
raise ValueError("NOVELAI_JWT is not set in `.env` file, please create one and set it")
credential = JwtCredential(jwt_token=SecretStr(jwt))
"""Or you can use the login credential to get the jwt token"""
_login_credential = Login.build(
user_name=os.getenv("NOVELAI_USER"),
password=os.getenv("NOVELAI_PASS")
_login_credential = LoginCredential(
username=os.getenv("NOVELAI_USER"),
password=SecretStr(os.getenv("NOVELAI_PASS"))
)
# await _login_credential.request()
print(f"Action List:{enum_to_list(Action)}")
Expand Down
13 changes: 7 additions & 6 deletions src/novelai_python/tool/paint_mask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import numpy as np


def create_mask_from_sketch(original_img_bytes: bytes,
sketch_img_bytes: bytes,
min_block_size: int = 15,
jagged_edges: bool = True,
output_format: str = '.png'
) -> bytes:
def create_mask_from_sketch(
original_img_bytes: bytes,
sketch_img_bytes: bytes,
min_block_size: int = 15,
jagged_edges: bool = True,
output_format: str = '.png'
) -> bytes:
"""
Function to create a mask from original and sketch images input as bytes. Returns BytesIO object.
Expand Down

0 comments on commit 1f8a9ac

Please sign in to comment.