-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
160 lines (147 loc) · 5.8 KB
/
Copy pathmain.py
File metadata and controls
160 lines (147 loc) · 5.8 KB
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
import os
import pickle
import tkinter as tk
from tkinter import filedialog
from plan import create_plan, create_plan_ipynb
config_file = os.path.join(os.getcwd(),"config.tccm")
def save_set(config):
if os.path.exists(config_file):
os.remove(config_file)
pickle.dump(config, open(config_file, "wb"))
def load_set():
return pickle.load(open(config_file,"rb"))
init_config={
"filepath":os.path.dirname(__file__),
"workpath":"/kaggle",
"saveas":os.path.dirname(__file__),
"title":"",
"vae":"",
"CivitAPI":"Please Insert CivitAI API",
"HuggingAPI":"Please Insert HuggingFace write API",
"UR":"User/Repo"}
if os.path.exists(config_file):
config=load_set()
else:
config=init_config
def about():
sub_win = tk.Toplevel()
sub_win.geometry("300x100")
label_sub = tk.Label(sub_win, text="Model Planner\nMade by Team C 2024")
label_sub.pack()
def cp(name):
try:
return config[name]
except:
return init_config[name]
def main():
win=tk.Tk()
menu=tk.Menu(win)
win.config(menu=menu)
menu_file = tk.Menu(win)
menu.add_cascade(label='Help', menu=menu_file)
menu_file.add_command(label='About', command=about)
win.geometry("330x360+100+120")
win.resizable(True, True)
win.title("Model Planner")
frame1 = tk.Frame(win)
frame0 = tk.Frame(win)
frame2 = tk.Frame(win)
frame3 = tk.Frame(win)
frame4 = tk.Frame(win)
frame5 = tk.Frame(win)
frame6 = tk.Frame(win)
frame7 = tk.Frame(win)
newlab = tk.Label(win, text="Model Planner", font = ('MS Gothic', 20))
lab = tk.Label(frame1, text="Planned Text Path", font = ('MS Gothic', 10))
lab0 = tk.Label(frame0, text="Workspace Path", font = ('MS Gothic', 10))
lab1 = tk.Label(frame2, text="Title", font = ('MS Gothic', 10))
lab2 = tk.Label(frame3, text="VAE Link", font = ('MS Gothic', 10))
lab3 = tk.Label(frame4, text="CivitAI API", font = ('MS Gothic', 10))
lab4 = tk.Label(frame5, text="HuggingFace API", font = ('MS Gothic', 10))
lab5 = tk.Label(frame6, text="User/Repo", font = ('MS Gothic', 10))
fileentry = tk.Entry(frame1)
fileentry.insert(0,cp("filepath"))
def filedialog_clicked():
fTyp = [("Text File","*.txt")]
iFile = cp("filepath")
iFilePath = filedialog.askopenfilename(filetypes = fTyp, title = "Select Planned File Path", initialdir = iFile)
fileentry.delete(0, tk.END)
fileentry.insert(tk.END, iFilePath)
config["filepath"] = iFilePath
filebutton = tk.Button(frame1, text="Open",command=filedialog_clicked)
wpath = tk.Entry(frame0,width=20)
wpath.insert(0,cp("workpath"))
title = tk.Entry(frame2,width=20)
title.insert(0,cp("title"))
vae = tk.Entry(frame3,width=20)
vae.insert(0,cp("vae"))
CAPI = tk.Entry(frame4,width=20)
CAPI.insert(0,cp("CivitAPI"))
HAPI = tk.Entry(frame5,width=20)
HAPI.insert(0,cp("HuggingAPI"))
UR = tk.Entry(frame6,width=20)
UR.insert(0,cp("UR"))
def save_as_text():
config["title"] = title.get()
config["workpath"] = wpath.get()
config["vae"] = vae.get()
config["CivitAPI"] = CAPI.get()
config["HuggingAPI"] = HAPI.get()
fTyp = [("Text File","*.txt")]
iFile = cp("saveas")
filename = filedialog.asksaveasfilename(initialdir = iFile,title = "Save as",filetypes = fTyp)
if not filename.endswith(".txt"):
filename += ".txt"
config["saveas"] = filename
if os.path.exists(filename):
os.remove(filename)
create_plan(**config)
save_set(config)
def save_as_ipynb():
config["title"] = title.get()
config["workpath"] = wpath.get()
config["vae"] = vae.get()
config["CivitAPI"] = CAPI.get()
config["HuggingAPI"] = HAPI.get()
config["UR"] = UR.get()
fTyp = [("IPYNB File","*.ipynb")]
iFile = cp("saveas")
filename = filedialog.asksaveasfilename(initialdir = iFile,title = "Save as",filetypes = fTyp)
if not filename.endswith(".ipynb"):
filename += ".ipynb"
config["saveas"] = filename
if os.path.exists(filename):
os.remove(filename)
create_plan_ipynb(**config)
save_set(config)
save = tk.Button(frame7, text="Save Plan As Text",command=save_as_text)
save1 = tk.Button(frame7, text="Save Plan As .ipynb",command=save_as_ipynb)
newlab.pack(anchor=tk.NW)
frame1.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab.pack(anchor=tk.NW)
fileentry.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
filebutton.pack(side=tk.LEFT)
frame0.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab0.pack(side=tk.LEFT)
wpath.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame2.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab1.pack(side=tk.LEFT)
title.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame3.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab2.pack(side=tk.LEFT)
vae.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame4.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab3.pack(side=tk.LEFT)
CAPI.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame5.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab4.pack(side=tk.LEFT)
HAPI.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame6.pack(anchor=tk.NW,expand=True,fill="x",pady=(10,0))
lab5.pack(side=tk.LEFT)
UR.pack(side=tk.LEFT,expand=True,fill="x",padx=(0,10))
frame7.pack(anchor=tk.S,expand=True,fill="x")
save.pack(side=tk.LEFT)
save1.pack(side=tk.RIGHT)
win.mainloop()
if __name__ == "__main__":
main()