-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from LlmKira/dev
/ai/upscale
- Loading branch information
Showing
18 changed files
with
419 additions
and
19 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
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,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2024/2/13 上午11:58 | ||
# @Author : sudoskys | ||
# @File : upscale.py | ||
# @Software: PyCharm | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2024/2/14 下午5:20 | ||
# @Author : sudoskys | ||
# @File : upscale_demo.py | ||
# @Software: PyCharm | ||
# To run the demo, you need an event loop, for instance by using asyncio | ||
import asyncio | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from pydantic import SecretStr | ||
|
||
from novelai_python import APIError, Upscale | ||
from novelai_python import UpscaleResp, JwtCredential | ||
from novelai_python.sdk.ai.generate_image import Action | ||
from novelai_python.utils.useful import enum_to_list | ||
|
||
load_dotenv() | ||
|
||
token = None | ||
jwt = os.getenv("NOVELAI_JWT") or token | ||
|
||
|
||
async def main(): | ||
globe_s = JwtCredential(jwt_token=SecretStr(jwt)) | ||
if not os.path.exists("generate_image.png"): | ||
raise FileNotFoundError("generate_image.png not found") | ||
with open("generate_image.png", "rb") as f: | ||
data = f.read() | ||
try: | ||
print(f"Action List:{enum_to_list(Action)}") | ||
upscale = Upscale(image=data) # Auto detect image size | base64 | ||
|
||
_res = await upscale.request( | ||
session=globe_s, remove_sign=True | ||
) | ||
except APIError as e: | ||
print(e.response) | ||
return | ||
|
||
# Meta | ||
_res: UpscaleResp | ||
print(_res.meta.endpoint) | ||
file = _res.files | ||
with open("upscale.py.png", "wb") as f: | ||
f.write(file[1]) | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2024/2/13 上午11:29 | ||
# @Author : sudoskys | ||
# @File : upscale.py | ||
# @Software: PyCharm | ||
from typing import Tuple | ||
|
||
from pydantic import BaseModel | ||
|
||
from ..schema import RespBase | ||
|
||
|
||
class UpscaleResp(RespBase): | ||
class RequestParams(BaseModel): | ||
endpoint: str | ||
raw_request: dict = None | ||
|
||
meta: RequestParams | ||
files: Tuple[str, bytes] = None |
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,11 @@ | ||
# -*- coding: utf-8 -*- | ||
# @Time : 2024/2/13 上午11:30 | ||
# @Author : sudoskys | ||
# @File : schema.py | ||
# @Software: PyCharm | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class RespBase(BaseModel): | ||
pass |
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
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
Oops, something went wrong.