Ex Data, Scientia

Home Contact

Building an AI-based image-classifier application

#!/home/username/gui_env/bin/python

from tkinter import filedialog
from tkinter import *

def clicked_5():
    btn_2.destroy()
    lbl_2.destroy()
    
    exec(open("Classify.py").read())
    print('Classification finished')
    window.destroy()
                        
def clicked_4():
    btn_1.destroy()
    lbl_1.destroy()
    
    global n_digits
    n_digits = str(txt_1.get())
    
    txt_1.destroy()
    
    global lbl_2
    lbl_2 = Label(window, text = 'Start classification. Application will close \n automatically once all images are classified.')
    lbl_2.grid(column = 0, row = 0)
    
    global btn_2
    btn_2 = Button(window, text = 'Confirm', bg = 'green', command = clicked_5)
    btn_2.grid(column=1, row=2)
                           
def clicked_3():
    btn_0.destroy()
    lbl_0.destroy()
    
    global weights_name
    weights_name = str(txt_0.get())
    
    txt_0.destroy()
    
    global lbl_1
    lbl_1 = Label(window, text = 'State number of classes')
    lbl_1.grid(column = 0, row = 0)
    
    global txt_1
    txt_1 = Entry(window, width = 40, bg = 'orange', textvariable = StringVar())
    txt_1.grid(column = 1, row = 1)

    global btn_1
    btn_1 = Button(window, text = 'Set', bg = 'green', command = clicked_4)
    btn_1.grid(column=1, row=2)
                    
def clicked_2():
    global lbl_0
    lbl_0 = Label(window, text = 'Enter model weights file name')
    lbl_0.grid(column = 0, row = 0)

    global txt_0
    txt_0 = Entry(window, width = 40, bg = 'orange', textvariable = StringVar())
    txt_0.grid(column = 1, row = 1)
    
    global btn_0
    btn_0 = Button(window, text = 'Confirm', bg = 'green', command = clicked_3)
    btn_0.grid(column=1, row=2)
                
def clicked_1():
    global weights_dir
    weights_dir = str(filedialog.askdirectory(title='Select model-weights directory', parent = window))+'/'
            
    clicked_2()
        
def clicked_0():
    if 'window' not in globals():
        global window
        window = Tk()
        window.geometry('700x200')
        window.title = 'Classification_GUI' 

    global sample_dir
    sample_dir = str(filedialog.askdirectory(title='Select folder of images to be classified', parent = window))+'/'
    
    clicked_1()                
                             
    window.mainloop()

clicked_0()