novelai-python 0.3.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {novelai_python-0.3.0 → novelai_python-0.3.1}/PKG-INFO +1 -1
- {novelai_python-0.3.0 → novelai_python-0.3.1}/pyproject.toml +1 -1
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/generate_image.py +8 -5
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/server.py +29 -1
- {novelai_python-0.3.0 → novelai_python-0.3.1}/LICENSE +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/NOTICE.MD +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/README.md +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_exceptions.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/generate_image.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/upscale.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/schema.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/information.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/login.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/subscription.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/ApiToken.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/JwtToken.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/UserAuth.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/_base.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/LICENSE +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/upscale.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/schema.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/information.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/login.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/subscription.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/encode.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/hash.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_artist.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_character.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_nsfw.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/useful.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/__init__.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_random_prompt.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_server.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_server_run.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_upscale.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_information.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_login.py +0 -0
- {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_subscription.py +0 -0
|
@@ -7,6 +7,7 @@ import base64
|
|
|
7
7
|
import json
|
|
8
8
|
import math
|
|
9
9
|
import random
|
|
10
|
+
from copy import deepcopy
|
|
10
11
|
from enum import Enum, IntEnum
|
|
11
12
|
from io import BytesIO
|
|
12
13
|
from typing import Optional, Union
|
|
@@ -249,7 +250,7 @@ class GenerateImageInfer(ApiBaseModel):
|
|
|
249
250
|
def validate_model(self):
|
|
250
251
|
if self.action == Action.INFILL and not self.parameters.mask:
|
|
251
252
|
logger.warning("Mask maybe required for infill mode.")
|
|
252
|
-
if self.action
|
|
253
|
+
if self.action != Action.GENERATE:
|
|
253
254
|
self.parameters.extra_noise_seed = self.parameters.seed
|
|
254
255
|
return self
|
|
255
256
|
|
|
@@ -394,6 +395,7 @@ class GenerateImageInfer(ApiBaseModel):
|
|
|
394
395
|
"Sec-Fetch-Site": "same-site",
|
|
395
396
|
"Pragma": "no-cache",
|
|
396
397
|
"Cache-Control": "no-cache",
|
|
398
|
+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0"
|
|
397
399
|
}
|
|
398
400
|
|
|
399
401
|
async def request(self,
|
|
@@ -421,20 +423,21 @@ class GenerateImageInfer(ApiBaseModel):
|
|
|
421
423
|
session.headers.clear()
|
|
422
424
|
session.headers.update(override_headers)
|
|
423
425
|
try:
|
|
424
|
-
_log_data = request_data
|
|
426
|
+
_log_data = deepcopy(request_data)
|
|
425
427
|
if self.action == Action.GENERATE:
|
|
426
428
|
logger.debug(f"Request Data: {_log_data}")
|
|
427
429
|
else:
|
|
428
430
|
_log_data.get("parameters", {}).update({
|
|
429
|
-
"image": "base64 data" if self.parameters.image else
|
|
431
|
+
"image": "base64 data" if self.parameters.image else None,
|
|
430
432
|
}
|
|
431
433
|
)
|
|
432
434
|
_log_data.get("parameters", {}).update(
|
|
433
435
|
{
|
|
434
|
-
"mask": "base64 data" if self.parameters.mask else
|
|
436
|
+
"mask": "base64 data" if self.parameters.mask else None,
|
|
435
437
|
}
|
|
436
438
|
)
|
|
437
|
-
logger.debug(f"Request Data: {
|
|
439
|
+
logger.debug(f"Request Data: {_log_data}")
|
|
440
|
+
del _log_data
|
|
438
441
|
except Exception as e:
|
|
439
442
|
logger.warning(f"Error when print log data: {e}")
|
|
440
443
|
try:
|
|
@@ -15,6 +15,7 @@ from starlette.responses import JSONResponse, StreamingResponse
|
|
|
15
15
|
|
|
16
16
|
from .credential import JwtCredential, SecretStr
|
|
17
17
|
from .sdk.ai.generate_image import GenerateImageInfer
|
|
18
|
+
from .sdk.ai.upscale import Upscale
|
|
18
19
|
from .sdk.user.information import Information
|
|
19
20
|
from .sdk.user.login import Login
|
|
20
21
|
from .sdk.user.subscription import Subscription
|
|
@@ -90,6 +91,33 @@ async def subscription(
|
|
|
90
91
|
return JSONResponse(status_code=500, content=e.__dict__)
|
|
91
92
|
|
|
92
93
|
|
|
94
|
+
@app.post("/ai/upscale")
|
|
95
|
+
async def upscale(
|
|
96
|
+
req: Upscale,
|
|
97
|
+
current_token: str = Depends(get_current_token)
|
|
98
|
+
):
|
|
99
|
+
"""
|
|
100
|
+
生成图片
|
|
101
|
+
:param current_token: Authorization
|
|
102
|
+
:param req: Upscale
|
|
103
|
+
:return:
|
|
104
|
+
"""
|
|
105
|
+
try:
|
|
106
|
+
_result = await req.request(session=get_session(current_token), remove_sign=True)
|
|
107
|
+
zip_file_bytes = io.BytesIO()
|
|
108
|
+
with zipfile.ZipFile(zip_file_bytes, mode="w", compression=zipfile.ZIP_DEFLATED) as zip_file:
|
|
109
|
+
file = _result.files # ONLY TUPLE
|
|
110
|
+
zip_file.writestr(zinfo_or_arcname=file[0], data=file[1])
|
|
111
|
+
# return the zip file
|
|
112
|
+
zip_file_bytes.seek(0)
|
|
113
|
+
return StreamingResponse(zip_file_bytes, media_type='application/zip', headers={
|
|
114
|
+
'Content-Disposition': 'attachment;filename=image.zip'
|
|
115
|
+
})
|
|
116
|
+
except Exception as e:
|
|
117
|
+
logger.exception(e)
|
|
118
|
+
return JSONResponse(status_code=500, content=e.__dict__)
|
|
119
|
+
|
|
120
|
+
|
|
93
121
|
@app.post("/ai/generate_image")
|
|
94
122
|
async def generate_image(
|
|
95
123
|
req: GenerateImageInfer,
|
|
@@ -110,7 +138,7 @@ async def generate_image(
|
|
|
110
138
|
# return the zip file
|
|
111
139
|
zip_file_bytes.seek(0)
|
|
112
140
|
return StreamingResponse(zip_file_bytes, media_type='application/zip', headers={
|
|
113
|
-
'Content-Disposition': 'attachment;filename=
|
|
141
|
+
'Content-Disposition': 'attachment;filename=image.zip'
|
|
114
142
|
})
|
|
115
143
|
except Exception as e:
|
|
116
144
|
logger.exception(e)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/generate_image.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/information.py
RENAMED
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/subscription.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_artist.py
RENAMED
|
File without changes
|
|
File without changes
|
{novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_nsfw.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|