-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgptopt.py
291 lines (232 loc) · 10.7 KB
/
gptopt.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
'''
code file: gptopt.py
8-9-2024 edit gptgui.ini in editor
'''
import os, sys
import configparser
import subprocess
from tkinter.font import Font
from ttkbootstrap import *
from ttkbootstrap.constants import *
from ttkbootstrap.tooltip import ToolTip
from ttkbootstrap.dialogs import Querybox
from tkinter import filedialog
from tkinter import messagebox
class Application(Frame):
''' main class docstring '''
def __init__(self, parent):
Frame.__init__(self, parent)
self.pack(fill=BOTH, expand=True, padx=4, pady=4)
self.create_widgets()
def create_widgets(self):
''' creates GUI for app '''
lbl = Label(self, text='Theme')
lbl.grid(row=1, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Save File Path')
lbl.grid(row=2, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Font Query Family')
lbl.grid(row=3, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Font Query Size')
lbl.grid(row=4, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Font Gpt Family')
lbl.grid(row=5, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Font Gpt Size')
lbl.grid(row=6, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Engine')
lbl.grid(row=7, column=1, sticky='e', pady=4, padx=4)
# lbl = Label(self, text='Temperature')
# lbl.grid(row=8, column=1, sticky='e', pady=4, padx=4)
# lbl = Label(self, text='Tokens')
# lbl.grid(row=9, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Gpt Key')
lbl.grid(row=10, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Time Elapsed')
lbl.grid(row=11, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Auto Save')
lbl.grid(row=12, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Top Frame Size')
lbl.grid(row=13, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Text editor')
lbl.grid(row=14, column=1, sticky='e', pady=4, padx=4)
lbl = Label(self, text='Temp file name')
lbl.grid(row=15, column=1, sticky='e', pady=4, padx=4)
self.vent_theme = StringVar()
ent_theme = Combobox(self, textvariable=self.vent_theme, width=10)
ent_theme['values'] = ('darkly',
'superhero',
'solar',
'cyborg',
'sandstone',
'yeti',
'pulse',
'cosmo',
'flatly',
'litera',
'minty',
'lumen',
'journal',
'simplex',
'cerculean')
ent_theme.current(0)
ent_theme.grid(row=1, column=2, sticky='w', pady=4, padx=4)
self.vent_path = StringVar()
ent_path = Entry(self, textvariable=self.vent_path, width=30)
ent_path.grid(row=2, column=2, sticky='w', pady=4, padx=4)
self.vent_fqfam = StringVar()
ent_fqfam = Entry(self, textvariable=self.vent_fqfam, width=12)
ent_fqfam.grid(row=3, column=2, sticky='w', pady=4, padx=4)
self.vent_fqsiz = StringVar()
ent_fqsiz = Entry(self, textvariable=self.vent_fqsiz, width=3)
ent_fqsiz.grid(row=4, column=2, sticky='w', pady=4, padx=4)
self.vent_fgfam = StringVar()
ent_fgfam = Entry(self, textvariable=self.vent_fgfam, width=12)
ent_fgfam.grid(row=5, column=2, sticky='w', pady=4, padx=4)
self.vent_fgsiz = StringVar()
ent_fgsiz = Entry(self, textvariable=self.vent_fgsiz, width=3)
ent_fgsiz.grid(row=6, column=2, sticky='w', pady=4, padx=4)
self.vcmbo_model = StringVar()
cmbo_model = Combobox(self, textvariable=self.vcmbo_model, width=20)
cmbo_model['values'] = (MyModels)
# ent_model.current(0)
cmbo_model.grid(row=7, column=2, sticky='w', pady=4, padx=4)
cmbo_model.bind('<<ComboboxSelected>>', self.onComboSelect)
# self.vcmbo_temp = StringVar()
# cmbo_temp = Combobox(self, textvariable=self.vcmbo_temp, width=6)
# cmbo_temp['values'] = ('0.7', '0.8', '0.9', '1.0', '1.2')
# # COMBO.bind('<<ComboboxSelected>>', self.ONCOMBOSELECT)
# # ent_model.current(0)
# cmbo_temp.grid(row=8, column=2, sticky='w', pady=4, padx=4)
# self.vent_token = StringVar()
# ent_token = Entry(self, textvariable=self.vent_token, width=6)
# ent_token.grid(row=9, column=2, sticky='w', pady=4, padx=4)
self.vent_gptkey = StringVar()
# self.vent_gptkey.trace("w", self.eventHandler)
self.ent_gptkey = Entry(self, textvariable=self.vent_gptkey, width=30)
self.ent_gptkey.grid(row=10, column=2, sticky='w', pady=4, padx=4)
self.vcb = IntVar()
cb = Checkbutton(self, variable=self.vcb, text='Check to show in output')
cb.grid(row=11, column=2, sticky=W, padx=5, pady=5)
self.vcv = IntVar()
cb = Checkbutton(self, variable=self.vcv, text='Check to turn on')
cb.grid(row=12, column=2, sticky=W, padx=5, pady=5)
self.vent_size = StringVar()
ent_size = Entry(self, textvariable=self.vent_size, width=4)
ent_size.grid(row=13, column=2, sticky='w', pady=4, padx=4)
self.vent_edit = StringVar()
ent_edit = Entry(self, textvariable=self.vent_edit)
ent_edit.grid(row=14, column=2, sticky='w', pady=4, padx=4)
self.vent_file = StringVar()
end_file = Entry(self, textvariable=self.vent_file)
end_file.grid(row=15, column=2, sticky='w', pady=4, padx=4)
# RIGHT SIDE
btn_path = Button(self, text='Browse', command=self.browse_path)
btn_path.grid(row=2, column=3, pady=4, padx=4)
btn_qfont = Button(self, text='Choose', command=self.browse_font1)
btn_qfont.grid(row=3, column=3, pady=4, padx=4)
btn_gfont = Button(self, text='Choose', command=self.browse_font2)
btn_gfont.grid(row=5, column=3, pady=4, padx=4)
btn_models = Button(self, text='Edit', command=self.edit_models)
btn_models.grid(row=7, column=3, pady=4, padx=4)
btn_close = Button(self, text='Save & Close', command=self.on_close)
btn_close.grid(row=15, column=3, pady=4, padx=4)
# set initial field values from ini file
self.vent_theme.set(MyTheme)
self.vent_path.set(MyPath)
self.vent_fqfam.set(MyFntQryF)
self.vent_fqsiz.set(MyFntQryZ)
self.vent_fgfam.set(MyFntGptF)
self.vent_fgsiz.set(MyFntGptZ)
self.vent_gptkey.set(MyKey)
self.vcmbo_model.set(MyModel)
self.vcb.set(MyTime)
self.vcv.set(MySave)
self.vent_size.set(MySize)
self.vent_edit.set(MyEditor)
self.vent_file.set(MyFile)
ToolTip(self.ent_gptkey,
text="Env Var or Key Literal",
bootstyle=(INFO, INVERSE))
ToolTip(btn_models,
text="Edit gptgui.ini\nin text editor",
bootstyle=(INFO, INVERSE))
def edit_models(self):
''' use MyEditor to edit gptgui.ini file
Notify user that the Options window will close '''
result = messagebox.askyesno("Attension",
"Options will Close.\nSave any changes first?")
subprocess.Popen([MyEditor, "gptgui.ini"])
if result:
self.on_close()
else:
root.destroy()
def browse_path(self):
''' browse with filedialog for directory '''
filename = filedialog.asksaveasfilename(initialdir = os.getcwd(),
title = "Select (create) Query-Save-File",
filetypes = (("text files","*.txt"),("all files","*.*")))
if filename is not None:
self.vent_path.set(filename)
def browse_font1(self):
''' Get font & size for query text '''
f = Querybox.get_font(parent=self)
self.vent_fqfam.set(f.cget("family"))
self.vent_fqsiz.set(str(f.cget("size")))
def browse_font2(self):
''' Get font & size for Gpt text '''
f = Querybox.get_font(parent=self)
self.vent_fgfam.set(f.cget("family"))
self.vent_fgsiz.set(str(f.cget("size")))
def onComboSelect(self, e):
''' pre set the tokens field for model '''
tok = self.vcmbo_model.get()
if tok == "gpt-3.5-turbo" :
self.vent_token.set("4097")
elif tok == "gpt-3.5-turbo-16k" :
self.vent_token.set("16385")
def on_close(self):
''' Save to gptgui.ini and close the window '''
config['Main']['fontqryfam'] = self.vent_fqfam.get()
config['Main']['fontqrysiz'] = self.vent_fqsiz.get()
config['Main']['fontgptfam'] = self.vent_fgfam.get()
config['Main']['fontgptsiz'] = self.vent_fgsiz.get()
config['Main']['gptkey'] = self.vent_gptkey.get().strip()
config['Main']['theme'] = self.vent_theme.get()
config['Main']['path'] = self.vent_path.get()
config['Main']['engine'] = self.vcmbo_model.get()
config['Main']['showtime'] = str(self.vcb.get())
config['Main']['autosave'] = str(self.vcv.get())
config['Main']['top_frame'] = str(self.vent_size.get())
config['Main']['editor'] = str(self.vent_edit.get())
config['Main']['tempfile'] = str(self.vent_file.get())
with open('gptgui.ini', 'w') as configfile:
config.write(configfile)
root.destroy()
config = configparser.ConfigParser()
config.read('gptgui.ini')
MyTheme = config['Main']['theme']
MyPath = config['Main']['path']
MyFntQryF = config['Main']['fontqryfam']
MyFntQryZ = config['Main']['fontqrysiz']
MyFntGptF = config['Main']['fontgptfam']
MyFntGptZ = config['Main']['fontgptsiz']
MyModel = config['Main']['engine']
MyKey = config['Main']['gptkey']
MyTime = config['Main']['showtime']
MySave = config['Main']['autosave']
MySize = config['Main']['top_frame']
MyEditor = config['Main']['editor']
MyFile = config['Main']['tempfile']
mods = config['Models']['list']
MyModels = mods.split(',')
MyModels = [s.strip() for s in MyModels]
# change working directory to path for this file
p = os.path.realpath(__file__)
os.chdir(os.path.dirname(p))
root = Window("GptGUI Options", MyTheme)
Sizegrip(root).place(rely=1.0, relx=1.0, x=0, y=0, anchor='se')
root.resizable(0, 0) # no resize & removes maximize button
root.iconphoto(False, PhotoImage(file='icon.png'))
root.attributes("-topmost", True) # Keep on top of other windows
# root.geometry("+100+20")
Application(root)
root.mainloop()