-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
205 lines (162 loc) · 5.22 KB
/
app.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
import customtkinter as ct
from tkinter.ttk import *
from tkinter.filedialog import askopenfile
import time
import pickle
#Modules
from modules.utils import *
from modules.DigitsTrain import CodeTraining
from modules.DigitsTrain import DigitTraining
from modules.SymbolTrain import SVMTraining
from modules.bubble_sheet import *
from modules.GradesSheet import *
# pytesseract.pytesseract.tesseract_cmd = (r"D:\Tesseract-OCR")
# Symbols Model
filename = 'SymbolsModel.sav'
# Training Model on Symbols (to be in the General/ Main Function)
# SVMmodel = SVMTraining()
# Save the model
# pickle.dump(SVMmodel, open(filename, 'wb'))
#Load Already Trained Model
SVMmodel = pickle.load(open(filename, 'rb'))
# Symbols Model
filename = 'Digits.sav'
# Training Model on Symbols (to be in the General/ Main Function)
# Digitsmodel = DigitTraining()
# Save the model
# pickle.dump(Digitsmodel, open(filename, 'wb'))
#Load Already Trained Model
Digitsmodel = pickle.load(open(filename, 'rb'))
# Codes Model
filename = 'Codes.sav'
# Training Model on Codes (to be in the General/ Main Function)
# Codemodel = CodeTraining()
# Save the model
# pickle.dump(Codemodel, open(filename, 'wb'))
#Load Already Trained Model
Codemodel = pickle.load(open(filename, 'rb'))
ct.set_appearance_mode("dark")
ct.set_default_color_theme("dark-blue")
root = ct.CTk()
root.geometry("700x500")
root.title("Grades Auto Filler")
# Frame
frame = ct.CTkFrame(master=root)
frame.pack(pady=20, padx=60, fill="both", expand=True)
radio_var = ct.IntVar()
checkbox_var = ct.IntVar()
checkbox_OCR_var = ct.IntVar()
index_var = ct.StringVar()
model = None
see_steps = False
data = {}
def handleCheckBox():
model = radio_var.get()
return
def open_file(which_file):
my_file = askopenfile(mode='r')
if (which_file == 0): # answers key file
data[0] = my_file.name
if (which_file == 1): # grades key file
data[1] = my_file.name
if (which_file == 2): # excel file
data[2] = my_file.name
if (which_file == 3): # image to be corrected
data[3] = my_file.name
return
def uploadFiles():
progressBar = ct.CTkProgressBar(
master=frame,
orientation="horizontal",
width=300,
height=5,
mode='determinate',
progress_color="lime"
)
progressBar.place(relx=0.28, rely=0.76, anchor="w")
progressBar.start()
for i in range(1):
frame.update_idletasks()
time.sleep(1)
progressBar.destroy()
ct.CTkLabel(master=frame, text='Files Uploaded Successfully!',
text_color="lime").place(relx=0.6, rely=0.8, anchor="w")
def handleRadioButton():
frame.update_idletasks()
return
def start():
model = radio_var.get()
data[4] = index_var.get()
data[5] = True if checkbox_OCR_var.get() == 1 else False
if (model == 1):
do_work(data, checkbox_var.get())
if (model == 2):
GradesSheet(data, SVM=SVMmodel, DSVM=Digitsmodel, CodeSVM=Codemodel)
else:
print('Please, choose a model to start.')
pass
# radio buttons
ct.CTkLabel(master=frame, text='Choose the model.',
text_color="lime").place(relx=0.2, rely=0.05, anchor="w")
radiobutton_1 = ct.CTkRadioButton(
master=frame, text="Bubble Sheet", variable=radio_var, value=1).place(relx=0.2, rely=0.1, anchor="w")
radiobutton_2 = ct.CTkRadioButton(
master=frame, text="Graded Sheet", variable=radio_var, value=2).place(relx=0.77, rely=0.1, anchor="e")
# Bubble sheet
ct.CTkLabel(master=frame, text='Bubble sheet files.',
text_color="lime").place(relx=0.2, rely=0.2, anchor="w")
inputFileUpload = ct.CTkButton(
master=frame,
text='Choose the answers key',
command=lambda: open_file(0)
).place(relx=0.2, rely=0.3, anchor="w")
imageUpload = ct.CTkButton(
master=frame,
text='Choose the image ',
command=lambda: open_file(3)
).place(relx=0.2, rely=0.4, anchor="w")
ExcelFileUpload = ct.CTkButton(
master=frame,
text='Choose the excel sheet',
command=lambda: open_file(2)
).place(relx=0.2, rely=0.5, anchor="w")
gradesKeyFileUpload = ct.CTkButton(
master=frame,
text='Choose the grades key',
command=lambda: open_file(1)
).place(relx=0.2, rely=0.6, anchor="w")
ExcelFileUpload = ct.CTkButton(
master=frame,
text='Submit Files',
command=lambda: uploadFiles()
).place(relx=0.4, rely=0.7, anchor="w")
checkbox = ct.CTkCheckBox(
master=frame,
text="See the steps.",
variable=checkbox_var,
onvalue=1,
offvalue=0
).place(relx=0.2, rely=0.8, anchor="w")
ExcelFileUpload = ct.CTkButton(
master=frame,
text='Start',
command=lambda: start()
).place(relx=0.4, rely=0.9, anchor="w")
# Table Grades
ct.CTkLabel(master=frame, text='Bubble sheet files.',
text_color="lime").place(relx=0.6, rely=0.2, anchor="w")
imageUpload = ct.CTkButton(
master=frame,
text='Choose the image',
command=lambda: open_file(3)
).place(relx=0.6, rely=0.3, anchor="w")
index_input = ct.CTkEntry(master=frame, textvariable=index_var, placeholder_text="Enter the index").place(
relx=0.6, rely=0.4, anchor="w")
checkbox = ct.CTkCheckBox(
master=frame,
text="OCR",
variable=checkbox_OCR_var,
onvalue=1,
offvalue=0
).place(relx=0.6, rely=0.5, anchor="w")
root.mainloop()