novelai-python 0.4.14__tar.gz → 0.4.16__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 (80) hide show
  1. {novelai_python-0.4.14 → novelai_python-0.4.16}/NOTICE.MD +1 -1
  2. {novelai_python-0.4.14 → novelai_python-0.4.16}/PKG-INFO +2 -2
  3. {novelai_python-0.4.14 → novelai_python-0.4.16}/pyproject.toml +1 -1
  4. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/_enum.py +55 -0
  5. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate_image/__init__.py +16 -29
  6. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_server_run.py +2 -2
  7. {novelai_python-0.4.14 → novelai_python-0.4.16}/LICENSE +0 -0
  8. {novelai_python-0.4.14 → novelai_python-0.4.16}/README.md +0 -0
  9. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/__init__.py +0 -0
  10. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_exceptions.py +0 -0
  11. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/__init__.py +0 -0
  12. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/__init__.py +0 -0
  13. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/generate.py +0 -0
  14. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/generate_image.py +0 -0
  15. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/generate_stream.py +0 -0
  16. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/generate_voice.py +0 -0
  17. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/ai/upscale.py +0 -0
  18. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/schema.py +0 -0
  19. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/user/__init__.py +0 -0
  20. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/user/information.py +0 -0
  21. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/user/login.py +0 -0
  22. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/_response/user/subscription.py +0 -0
  23. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/credential/ApiToken.py +0 -0
  24. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/credential/JwtToken.py +0 -0
  25. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/credential/UserAuth.py +0 -0
  26. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/credential/__init__.py +0 -0
  27. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/credential/_base.py +0 -0
  28. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/__init__.py +0 -0
  29. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/LICENSE +0 -0
  30. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/__init__.py +0 -0
  31. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/_const.py +0 -0
  32. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/_cost.py +0 -0
  33. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/augment_image/__init__.py +0 -0
  34. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/augment_image/_enum.py +0 -0
  35. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate/__init__.py +0 -0
  36. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate/_const.py +0 -0
  37. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate/_enum.py +0 -0
  38. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate/_preset.py +0 -0
  39. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate_image/suggest_tags.py +0 -0
  40. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate_stream.py +0 -0
  41. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate_voice/__init__.py +0 -0
  42. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/generate_voice/_enum.py +0 -0
  43. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/ai/upscale.py +0 -0
  44. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/schema.py +0 -0
  45. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/user/__init__.py +0 -0
  46. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/user/information.py +0 -0
  47. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/user/login.py +0 -0
  48. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/sdk/user/subscription.py +0 -0
  49. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/server.py +0 -0
  50. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/NOTICE.MD +0 -0
  51. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/__init__.py +0 -0
  52. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/bpe_simple_vocab_16e6.txt.gz +0 -0
  53. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/gpt2-genji_tokenizer.json +0 -0
  54. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/gpt2_tokenizer.json +0 -0
  55. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/nerdstash_v1.model +0 -0
  56. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/nerdstash_v2.model +0 -0
  57. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/novelai.model +0 -0
  58. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/novelai_v2.model +0 -0
  59. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/pile_tokenizer.json +0 -0
  60. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tokenizer/simple_tokenizer.py +0 -0
  61. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/__init__.py +0 -0
  62. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/image_metadata/__init__.py +0 -0
  63. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/image_metadata/lsb_extractor.py +0 -0
  64. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/image_metadata/lsb_injector.py +0 -0
  65. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/paint_mask/__init__.py +0 -0
  66. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/random_prompt/__init__.py +0 -0
  67. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/random_prompt/tag.py +0 -0
  68. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/random_prompt/tag_character.py +0 -0
  69. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/tool/random_prompt/tag_nsfw.py +0 -0
  70. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/utils/__init__.py +0 -0
  71. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/utils/encode.py +0 -0
  72. {novelai_python-0.4.14 → novelai_python-0.4.16}/src/novelai_python/utils/useful.py +0 -0
  73. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/__init__.py +0 -0
  74. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_generate_voice.py +0 -0
  75. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_random_prompt.py +0 -0
  76. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_server.py +0 -0
  77. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_upscale.py +0 -0
  78. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_user_information.py +0 -0
  79. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_user_login.py +0 -0
  80. {novelai_python-0.4.14 → novelai_python-0.4.16}/tests/test_user_subscription.py +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
  The MIT license applies to the files in:
6
6
 
7
- file: "src/novelai_python/sdk/ai/generate_image.py" from https://github.com/HanaokaYuzu/NovelAI-API
7
+ file: "src/novelai_python/sdk/ai/generate-image.py" from https://github.com/HanaokaYuzu/NovelAI-API
8
8
  file: "src/novelai_python/tokenizer/novelai.model" from https://github.com/NovelAI/novelai-tokenizer
9
9
  file: "src/novelai_python/tokenizer/novelai_v2.model from https://github.com/NovelAI/novelai-tokenizer
10
10
  file: "src/novelai_python/tool/image_metadata/lsb_injector.py" from https://github.com/NovelAI/novelai-image-metadata
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: novelai-python
3
- Version: 0.4.14
3
+ Version: 0.4.16
4
4
  Summary: NovelAI Python Binding With Pydantic
5
5
  Author-Email: sudoskys <coldlando@hotmail.com>
6
6
  License: Apache License 2.0
@@ -27,9 +27,9 @@ Requires-Dist: pynacl>=1.5.0
27
27
  Requires-Dist: ftfy>=6.2.0
28
28
  Requires-Dist: regex>=2023.12.25
29
29
  Requires-Dist: tokenizers>=0.15.2
30
+ Provides-Extra: testing
30
31
  Requires-Dist: pytest>=7.4.4; extra == "testing"
31
32
  Requires-Dist: pytest-asyncio>=0.23.4; extra == "testing"
32
- Provides-Extra: testing
33
33
  Description-Content-Type: text/markdown
34
34
 
35
35
  ![banner](https://github.com/LlmKira/novelai-python/blob/dev/playground/banner-raw.png?raw=true)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "novelai-python"
3
- version = "0.4.14"
3
+ version = "0.4.16"
4
4
  description = "NovelAI Python Binding With Pydantic"
5
5
  authors = [
6
6
  { name = "sudoskys", email = "coldlando@hotmail.com" },
@@ -6,6 +6,8 @@
6
6
  from enum import Enum, IntEnum
7
7
  from typing import List
8
8
 
9
+ from pydantic.dataclasses import dataclass
10
+
9
11
 
10
12
  class Sampler(Enum):
11
13
  PLMS = "plms"
@@ -170,6 +172,8 @@ class ModelGroups(Enum):
170
172
 
171
173
 
172
174
  def get_model_group(model: str) -> ModelGroups:
175
+ if isinstance(model, Enum):
176
+ model = model.value
173
177
  mapping = {
174
178
  "stable-diffusion": ModelGroups.STABLE_DIFFUSION,
175
179
  "nai-diffusion": ModelGroups.STABLE_DIFFUSION,
@@ -212,8 +216,59 @@ PROMOTION = {
212
216
  "Stable Diffusion F1022D28": Model.NAI_DIFFUSION_2,
213
217
  "Stable Diffusion XL B0BDF6C1": Model.NAI_DIFFUSION_3,
214
218
  "Stable Diffusion XL C1E1DE52": Model.NAI_DIFFUSION_3,
219
+ "Stable Diffusion XL 7BCCAA2C": Model.NAI_DIFFUSION_3,
215
220
  "Stable Diffusion XL 8BA2AF87": Model.NAI_DIFFUSION_3,
216
221
  "Stable Diffusion XL 4BE8C60C": Model.NAI_DIFFUSION_FURRY_3,
217
222
  "Stable Diffusion XL C8704949": Model.NAI_DIFFUSION_FURRY_3,
223
+ "Stable Diffusion XL 37C2B166": Model.NAI_DIFFUSION_FURRY_3,
218
224
  "Stable Diffusion XL 9CC2F394": Model.NAI_DIFFUSION_FURRY_3,
219
225
  }
226
+
227
+
228
+ def get_default_uc_preset(model: str, uc_preset: int) -> str:
229
+ if isinstance(model, Enum):
230
+ model = model.value
231
+ if isinstance(uc_preset, Enum):
232
+ uc_preset = uc_preset.value
233
+
234
+ @dataclass
235
+ class UcPrompt:
236
+ label: str
237
+ text: str
238
+
239
+ mapper = {
240
+ ModelGroups.STABLE_DIFFUSION: [
241
+ UcPrompt("lowQualityPlusBadAnatomy",
242
+ text="lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"),
243
+ UcPrompt("lowQuality",
244
+ text="lowres, text, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"),
245
+ UcPrompt("none", text="lowres")
246
+ ],
247
+ ModelGroups.STABLE_DIFFUSION_GROUP_2: [
248
+ UcPrompt("heavy",
249
+ text="lowres, bad, text, error, missing, extra, fewer, cropped, jpeg artifacts, worst quality, bad quality, watermark, displeasing, unfinished, chromatic aberration, scan, scan artifacts"),
250
+ UcPrompt("light", text="lowres, jpeg artifacts, worst quality, watermark, blurry, very displeasing"),
251
+ UcPrompt("none", text="lowres")
252
+ ],
253
+ ModelGroups.STABLE_DIFFUSION_XL: [
254
+ UcPrompt("heavy",
255
+ text="lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]"),
256
+ UcPrompt("light", text="lowres, jpeg artifacts, worst quality, watermark, blurry, very displeasing"),
257
+ UcPrompt("humanFocus",
258
+ text="lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract], bad anatomy, bad hands, @_@, mismatched pupils, heart-shaped pupils, glowing eyes"),
259
+ UcPrompt("none", text="lowres")
260
+ ],
261
+ ModelGroups.STABLE_DIFFUSION_XL_FURRY: [
262
+ UcPrompt("heavy",
263
+ text="{{worst quality}}, [displeasing], {unusual pupils}, guide lines, {{unfinished}}, {bad}, url, artist name, {{tall image}}, mosaic, {sketch page}, comic panel, impact (font), [dated], {logo}, ych, {what}, {where is your god now}, {distorted text}, repeated text, {floating head}, {1994}, {widescreen}, absolutely everyone, sequence, {compression artifacts}, hard translated, {cropped}, {commissioner name}, unknown text, high contrast"),
264
+ UcPrompt("light",
265
+ text="{worst quality}, guide lines, unfinished, bad, url, tall image, widescreen, compression artifacts, unknown text"),
266
+ UcPrompt("none", text="lowres")
267
+ ],
268
+ }
269
+ model_group = get_model_group(model)
270
+ prompts: List[UcPrompt] = mapper.get(model_group, [UcPrompt("none", "lowres")])
271
+ if 0 <= uc_preset < len(prompts):
272
+ return prompts[uc_preset].text
273
+ else:
274
+ return "lowres"
@@ -25,7 +25,7 @@ from typing_extensions import override
25
25
 
26
26
  from novelai_python.sdk.ai._cost import CostCalculator
27
27
  from novelai_python.sdk.ai._enum import Model, Sampler, NoiseSchedule, ControlNetModel, Action, UCPreset, \
28
- INPAINTING_MODEL_LIST, get_default_noise_schedule, get_supported_noise_schedule
28
+ INPAINTING_MODEL_LIST, get_default_noise_schedule, get_supported_noise_schedule, get_default_uc_preset
29
29
  from ...schema import ApiBaseModel
30
30
  from ...._exceptions import APIError, AuthError, ConcurrentGenerationError, SessionHttpError
31
31
  from ...._response.ai.generate_image import ImageGenerateResp, RequestParams
@@ -138,8 +138,8 @@ class Params(BaseModel):
138
138
  # TODO: find out the usage
139
139
  steps: Optional[int] = Field(23, ge=1, le=50)
140
140
  """Steps"""
141
- ucPreset: Optional[UCPreset] = 0
142
- """The Negative Prompt Preset"""
141
+ ucPreset: Optional[Union[UCPreset, int]] = Field(None, ge=0)
142
+ """The Negative Prompt Preset, Bigger or equal to 0"""
143
143
  uncond_scale: Optional[float] = Field(1.0, ge=0, le=1.5, multiple_of=0.05)
144
144
  """Undesired Content Strength"""
145
145
  width: Optional[int] = Field(832, ge=64, le=49152)
@@ -324,7 +324,7 @@ class GenerateImageInfer(ApiBaseModel):
324
324
 
325
325
  action: Union[str, Action] = Field(Action.GENERATE, description="Mode for img generate")
326
326
  input: str = "1girl, best quality, amazing quality, very aesthetic, absurdres"
327
- model: Optional[Model] = "nai-diffusion-3"
327
+ model: Optional[Union[Model, str]] = "nai-diffusion-3"
328
328
  parameters: Params = Params()
329
329
  model_config = ConfigDict(extra="ignore")
330
330
 
@@ -336,32 +336,18 @@ class GenerateImageInfer(ApiBaseModel):
336
336
  :param args: Any
337
337
  :return: None
338
338
  """
339
+ # Must be a string
339
340
  if self.parameters.negative_prompt is None:
340
341
  self.parameters.negative_prompt = ""
341
- if self.parameters.ucPreset == 0:
342
- # 0: 重型
343
- self.parameters.negative_prompt = (
344
- "lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, "
345
- "watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, "
346
- "username, scan, [abstract], bad anatomy, bad hands, @_@, mismatched pupils, heart-shaped pupils, "
347
- "glowing eyes, lowres, bad anatomy, bad hands, text, error, missing fingers, "
348
- "extra digit, fewer digits, cropped, worst quality, low quality, normal quality, "
349
- f"jpeg artifacts, signature, watermark, username, blurry "
350
- f",{self.parameters.negative_prompt}"
342
+
343
+ # Add negative prompt based on ucPreset
344
+ if self.parameters.ucPreset is not None:
345
+ default_negative_prompt = get_default_uc_preset(self.model, self.parameters.ucPreset)
346
+ self.parameters.negative_prompt = ", ".join(
347
+ filter(None, [default_negative_prompt, self.parameters.negative_prompt])
351
348
  )
352
- elif self.parameters.ucPreset == 1:
353
- # 1: 轻型
354
- self.parameters.negative_prompt = (f"lowres, jpeg artifacts, worst quality, watermark, blurry, "
355
- f"very displeasing"
356
- f",{self.parameters.negative_prompt}")
357
- elif self.parameters.ucPreset == 2:
358
- # 2: 人物
359
- self.parameters.negative_prompt = ("lowres, {bad}, error, fewer, extra, missing, worst quality, "
360
- "jpeg artifacts, bad quality, watermark, unfinished, displeasing, "
361
- "chromatic aberration, signature, extra digits, artistic error, "
362
- "username, scan, [abstract], bad anatomy, bad hands, @_@, mismatched "
363
- f"pupils, heart-shaped pupils, glowing eyes "
364
- f",{self.parameters.negative_prompt}")
349
+
350
+ # Add quality prompt
365
351
  if self.parameters.qualityToggle:
366
352
  self.input += ", best quality, amazing quality, very aesthetic, absurdres"
367
353
 
@@ -434,7 +420,7 @@ class GenerateImageInfer(ApiBaseModel):
434
420
  model: Union[Model, str] = "nai-diffusion-3",
435
421
  action: Union[Action, str] = 'generate',
436
422
  negative_prompt: str = "",
437
- ucPreset: Union[UCPreset, int] = UCPreset.TYPE0,
423
+ ucPreset: Optional[Union[UCPreset, int]] = UCPreset.TYPE0,
438
424
  steps: int = 28,
439
425
  seed: int = None,
440
426
  scale: float = 5.0,
@@ -470,7 +456,8 @@ class GenerateImageInfer(ApiBaseModel):
470
456
  :param decrisp_mode: Reduce artifacts caused by high prompt guidance values.
471
457
  减少由高提示引导值引起的伪影。
472
458
  :param variety_boost: A new feature to improve the diversity of samples.
473
- 一项新功能,用于提高样本的多样性。
459
+ Variety Boost means your negative prompt will only be used after the body shape has been decided.
460
+ 一项新功能,用于提高样本的多样性。但是,这意味着您的负面提示只会在身体形状确定后使用。
474
461
  :param reference_information_extracted_multiple: The reference information extracted for Vibe mode.
475
462
  Vibe模式的提取的参考信息。
476
463
  :param reference_image_multiple: The reference image for Vibe mode.
@@ -29,8 +29,8 @@ def test_subscription_without_api_key(mock_subscription):
29
29
  @patch('src.novelai_python.server.GenerateImageInfer')
30
30
  def test_generate_image_without_api_key(mock_generate_image):
31
31
  mock_generate_image.return_value.request.return_value = {"status": "image generated"}
32
- response = client.post("/ai/generate_image")
33
- assert response.status_code == 404
32
+ response = client.post("/ai/generate-image")
33
+ assert response.status_code == 403
34
34
 
35
35
 
36
36
  def test_get_session_new_token():
File without changes