Skip to content

Commit

Permalink
Update ai_tag_extractor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JingShing committed Nov 15, 2022
1 parent 185726a commit 4074075
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions script/ai_tag_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self):
self.root = Tk()
self.frame = None
self.frame_index = 0
self.root.geometry('450x350')
self.root.geometry('500x350')
self.root.title('Tag Extractor')
self.root.protocol("WM_DELETE_WINDOW", self.quit)
# maker info
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, master):
self.data_dict = {}
self.novelai_dict = {}
self.all_text = Text(self, width=30, height=10)
self.all_text.grid(column=2, row=0, sticky=N+W, columnspan=2, rowspan=5)
self.all_text.grid(column=2, row=0, sticky=N+W, columnspan=3, rowspan=5)
self.all_label = Label(self, text="all info")
self.all_label.grid(column=2, row=3)

Expand All @@ -70,7 +70,19 @@ def __init__(self, master):
self.import_button.grid(column=0, row=6, sticky=N+W)
self.save_button = Button(self, text='save', command=self.save_set)
self.save_button.grid(column=1, row=6, sticky=N+W)
self.clear_button = Button(self, text='clear', command=self.text_clear)
self.clear_button.grid(column=2, row=6, sticky=N+W)

self.status_name = StringVar()
self.status = 'None'
self.now_status_str = 'Now status : '
self.status_display = Label(self, textvariable=self.status_name)
self.status_display.grid(column=0, row=7, sticky=N+W, rowspan=3)
self.set_label_text()

def set_label_text(self):
self.status_name.set(self.now_status_str + self.status)

def add_text(self, text):
if type(text) == dict:
if 'Title' in text:# for novelai image
Expand All @@ -93,6 +105,8 @@ def text_clear(self):
self.prompt_text.delete(1.0, 'end')
self.negative_text.delete(1.0, 'end')
self.parameter_text.delete(1.0, 'end')
self.status = 'had clear'
self.set_label_text()

def get_info(self):# use info dict to get info
if 'Title' in self.novelai_dict:# for novelai image
Expand All @@ -116,17 +130,23 @@ def dict_to_text(self, dict1):# change info dict to txt format

def import_set(self):# import image to get info
set_path = filedialog.askopenfilename(filetypes = (("png file","*.png"),("all files","*.*")))
self.status = 'loading'
self.set_label_text()
if set_path:
self.text_clear()# now will clear text box after import
im = Image.open(set_path)
im.load()
self.data_dict['file_name'] = set_path.split('/')[-1].split('.')[0]
self.add_text(im.info)
self.status = 'had imported set'
self.set_label_text()

def save_set(self):# save to txt
f = open(self.data_dict['file_name'] + ".txt", "w")
f.write(str(self.data_dict['spell']))
f.close()
self.status = 'save complete'
self.set_label_text()

main = Gui_helper_main()
main.run()

0 comments on commit 4074075

Please sign in to comment.