Skip to content

Commit

Permalink
✨ feat(playground): add cost calculation for VIP3 users
Browse files Browse the repository at this point in the history
✨ feat(playground): add cost calculation for VIP3 users

- Added cost calculation for VIP3 users in the `generate_image.py` file
- Output the charge amount if the user is a VIP3 member
  • Loading branch information
sudoskys committed Feb 8, 2024
1 parent b88fe4b commit 2156d08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The goal of this repository is to use Pydantic to build legitimate requests to a
- [x] /ai/generate-image
- [x] /user/subscription
- [x] /user/login
- [x] /user/information
- [ ] /ai/generate-image/suggest-tags
- [ ] /ai/annotate-image
- [ ] /ai/classify
Expand All @@ -29,7 +30,7 @@ import os
from dotenv import load_dotenv
from pydantic import SecretStr

from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential, LoginCredential
from novelai_python import GenerateImageInfer, ImageGenerateResp, JwtCredential, LoginCredential, ApiCredential

load_dotenv()

Expand All @@ -38,18 +39,26 @@ enhance = "year 2023,dynamic angle, best quality, amazing quality, very aesthet

async def main():
globe_s = JwtCredential(
jwt_token=SecretStr(os.getenv("NOVELAI_JWT"))
jwt_token=SecretStr(os.getenv("NOVELAI_JWT")) # ey****
)
globe_s1 = ApiCredential(
api_token=SecretStr(os.getenv("NOVELAI_JWT")) # pst-***
)
globe_s2 = LoginCredential(
username=os.getenv("NOVELAI_USERNAME"),
password=SecretStr(os.getenv("NOVELAI_PASSWORD"))
)
_res = await GenerateImageInfer.build(
prompt=f"1girl,{enhance}").generate(
session=globe_s)
_res: ImageGenerateResp
print(_res.meta)
file = _res.files[0]

gen = await GenerateImageInfer.build(
prompt=f"1girl,{enhance}")
cost = gen.calculate_cost(is_opus=True)
print(f"charge: {cost} if you are vip3")

resp = gen.generate(session=globe_s)
resp: ImageGenerateResp
print(resp.meta)

file = resp.files[0]
with open(file[0], "wb") as f:
f.write(file[1])

Expand Down
2 changes: 2 additions & 0 deletions playground/generate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ async def main():
try:
gen = GenerateImageInfer.build(
prompt=f"1girl, winter, jacket, sfw, angel, flower,{enhance}")
cost = gen.calculate_cost(is_opus=True)
print(f"charge: {cost} if you are vip3")
print(f"charge: {gen.calculate_cost(is_opus=True)}")
_res = await gen.generate(
session=globe_s, remove_sign=True
Expand Down

0 comments on commit 2156d08

Please sign in to comment.