-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_settings.py
144 lines (112 loc) · 6.19 KB
/
package_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# This example demonstrates how to create a simple dialog in Anchorpoint
from datetime import timedelta
import anchorpoint as ap
import os
from ai.api import check_usage
from common.settings import tagger_settings
def delete_api_key_callback(dialog: ap.Dialog):
tagger_settings.openai_api_key = ""
dialog.set_value("openai_api_key", "")
tagger_settings.store()
def delete_admin_api_key_callback(dialog: ap.Dialog):
tagger_settings.openai_api_admin_key = ""
dialog.set_value("openai_api_admin_key", "")
tagger_settings.store()
def check_usage_callback(dialog: ap.Dialog):
today = check_usage(timedelta(days=1))
dialog.set_value("usage_today", today)
value = check_usage(timedelta(days=7))
dialog.set_value("usage_week", value)
def apply_callback(dialog: ap.Dialog):
openai_api_key = str(dialog.get_value("openai_api_key"))
tagger_settings.openai_api_key = openai_api_key
openai_api_admin_key = str(dialog.get_value("openai_api_admin_key"))
tagger_settings.openai_api_admin_key = openai_api_admin_key
tagger_settings.file_label_ai_types = bool(dialog.get_value("file_label_ai_types"))
tagger_settings.file_label_ai_genres = bool(dialog.get_value("file_label_ai_genres"))
tagger_settings.file_label_ai_objects = bool(dialog.get_value("file_label_ai_objects"))
tagger_settings.file_label_ai_objects_min = int(str(dialog.get_value("file_label_ai_objects_min")))
tagger_settings.file_label_ai_objects_max = int(str(dialog.get_value("file_label_ai_objects_max")))
tagger_settings.folder_use_ai_engines = bool(dialog.get_value("folder_use_ai_engines"))
tagger_settings.folder_use_ai_types = bool(dialog.get_value("folder_use_ai_types"))
tagger_settings.folder_use_ai_genres = bool(dialog.get_value("folder_use_ai_genres"))
tagger_settings.debug_log = bool(dialog.get_value("debug_log"))
tagger_settings.store()
ap.UI().show_success("Settings Updated")
dialog.close()
def main():
# Create a dialog container
dialog = ap.Dialog()
dialog.title = "AI Tagging Settings"
ctx = ap.get_context()
if ctx.icon:
dialog.icon = ctx.icon
dialog.add_text("<b>OpenAI API Key</b>")
try:
openai_api_key = tagger_settings.openai_api_key
except KeyError:
openai_api_key = ""
dialog.add_input(
openai_api_key, var="openai_api_key", width=400, placeholder="sk-proj-45jdh5k3kjdh5k3jh54kjh3...",
password=True).add_button("Delete", callback=delete_api_key_callback)
dialog.add_info(
"An API key is an identifier (similar to username and password), that<br>allows you to access the AI-cloud services from OpenAI. Create an<br>API key on <a href='https://platform.openai.com/settings/organization/api-keys'>the Open AI website</a>. You will need to set up billing first.")
dialog.start_section("File Settings", folded=False)
dialog.add_checkbox(tagger_settings.file_label_ai_types, var="file_label_ai_types", text="Label Types")
dialog.add_info("e.g. model, texture, sfx")
dialog.add_checkbox(tagger_settings.file_label_ai_genres, var="file_label_ai_genres", text="Label Genres")
dialog.add_info("e.g. casual, cyberpunk, steampunk")
(
dialog.add_checkbox(tagger_settings.file_label_ai_objects, var="file_label_ai_objects", text="Label Objects\t")
.add_text("Count:")
.add_input(str(tagger_settings.file_label_ai_objects_min), var="file_label_ai_objects_min", width=50)
.add_text("-")
.add_input(str(tagger_settings.file_label_ai_objects_max), var="file_label_ai_objects_max", width=50)
)
dialog.add_info("What's in the picture. For example, an axe, a car, a character")
dialog.add_separator()
dialog.end_section()
dialog.start_section("Folder Settings", folded=False)
dialog.add_info("This will check the content of the folder, including all subfolders")
dialog.add_checkbox(tagger_settings.folder_use_ai_engines, var="folder_use_ai_engines", text="Label Engines")
dialog.add_info("e.g. Unity, Unreal, Godot")
dialog.add_checkbox(tagger_settings.folder_use_ai_types, var="folder_use_ai_types", text="Label Types")
dialog.add_info("e.g. model, texture, sfx")
dialog.add_checkbox(tagger_settings.folder_use_ai_genres, var="folder_use_ai_genres", text="Label Genres")
dialog.add_info("e.g. casual, cyberpunk, steampunk")
dialog.add_separator()
dialog.end_section()
dialog.start_section("Admin", folded=True)
dialog.add_text("<b>OpenAI Admin API Key</b>")
try:
openai_api_admin_key = tagger_settings.openai_api_admin_key
except KeyError:
openai_api_admin_key = ""
(dialog.add_input(
openai_api_admin_key, var="openai_api_admin_key", width=400,
placeholder="sk-admin-45jdh5k3kjdh5k3jh54kjh3...", password=True)
.add_button("Delete", callback=delete_admin_api_key_callback))
dialog.add_info(
"(Optional) Add the Admin key to be able to see your usage <br>"
"Create an Admin API key on <a href='https://platform.openai.com/settings/organization/admin-keys'>"
"the Open AI website</a>")
dialog.add_button("Check usage", callback=check_usage_callback)
dialog.add_text("Usage today:").add_text("---", var="usage_today")
dialog.add_text("Usage last 7 days:").add_text("---", var="usage_week")
dialog.add_separator()
dialog.end_section()
debug_folded = not tagger_settings.debug_log
dialog.start_section("Debugging", folded=debug_folded)
dialog.add_checkbox(tagger_settings.debug_log, var="debug_log", text="Enable Extended Logging")
dialog.add_info("Log additional information to the console (open with CTRL+SHIFT+P)")
dialog.add_separator()
dialog.end_section()
dialog.add_info(
"Monitor your <a href='https://platform.openai.com/settings/organization/api-keys'>API keys</a> "
"and <a href='https://platform.openai.com/settings/organization/usage'>current spending</a> on the "
"OpenAI website. This<br> Action was created by <b>Hermesis Trismegistus</b>.If you like it, "
"feel free to<br><a href='https://ko-fi.com/hermesistrismegistus'>make a donation.</a>")
dialog.add_button("Apply", callback=apply_callback)
dialog.show()
if __name__ == "__main__":
main()