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.
Files changed (49) hide show
  1. {novelai_python-0.3.0 → novelai_python-0.3.1}/PKG-INFO +1 -1
  2. {novelai_python-0.3.0 → novelai_python-0.3.1}/pyproject.toml +1 -1
  3. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/generate_image.py +8 -5
  4. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/server.py +29 -1
  5. {novelai_python-0.3.0 → novelai_python-0.3.1}/LICENSE +0 -0
  6. {novelai_python-0.3.0 → novelai_python-0.3.1}/NOTICE.MD +0 -0
  7. {novelai_python-0.3.0 → novelai_python-0.3.1}/README.md +0 -0
  8. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/__init__.py +0 -0
  9. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_exceptions.py +0 -0
  10. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/__init__.py +0 -0
  11. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/__init__.py +0 -0
  12. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/generate_image.py +0 -0
  13. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/ai/upscale.py +0 -0
  14. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/schema.py +0 -0
  15. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/__init__.py +0 -0
  16. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/information.py +0 -0
  17. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/login.py +0 -0
  18. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/_response/user/subscription.py +0 -0
  19. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/ApiToken.py +0 -0
  20. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/JwtToken.py +0 -0
  21. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/UserAuth.py +0 -0
  22. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/__init__.py +0 -0
  23. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/credential/_base.py +0 -0
  24. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/__init__.py +0 -0
  25. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/LICENSE +0 -0
  26. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/__init__.py +0 -0
  27. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/ai/upscale.py +0 -0
  28. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/schema.py +0 -0
  29. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/__init__.py +0 -0
  30. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/information.py +0 -0
  31. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/login.py +0 -0
  32. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/sdk/user/subscription.py +0 -0
  33. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/__init__.py +0 -0
  34. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/encode.py +0 -0
  35. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/hash.py +0 -0
  36. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/__init__.py +0 -0
  37. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag.py +0 -0
  38. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_artist.py +0 -0
  39. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_character.py +0 -0
  40. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/random_prompt/tag_nsfw.py +0 -0
  41. {novelai_python-0.3.0 → novelai_python-0.3.1}/src/novelai_python/utils/useful.py +0 -0
  42. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/__init__.py +0 -0
  43. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_random_prompt.py +0 -0
  44. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_server.py +0 -0
  45. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_server_run.py +0 -0
  46. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_upscale.py +0 -0
  47. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_information.py +0 -0
  48. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_login.py +0 -0
  49. {novelai_python-0.3.0 → novelai_python-0.3.1}/tests/test_user_subscription.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: novelai-python
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Novelai Python Binding With Pydantic
5
5
  Author-Email: sudoskys <coldlando@hotmail.com>
6
6
  License: Apache License 2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "novelai-python"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Novelai Python Binding With Pydantic"
5
5
  authors = [
6
6
  { name = "sudoskys", email = "coldlando@hotmail.com" },
@@ -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 == Action.INFILL:
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.copy()
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 "None",
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 "None",
436
+ "mask": "base64 data" if self.parameters.mask else None,
435
437
  }
436
438
  )
437
- logger.debug(f"Request Data: {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=multiple_files.zip'
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