-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
96 lines (76 loc) · 2.73 KB
/
Copy pathgui.py
File metadata and controls
96 lines (76 loc) · 2.73 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
import tkinter as tk
from tkinter import *
from tkinter import filedialog
from turtle import bgcolor
from PIL import ImageTk, Image
from test_handwriting import Handwriting
from autocorrect import Speller
from wordsearcher import WordSearcher
class App(tk.Tk):
def __init__(self) -> None:
"""
sets up the window and frames that hold the image and text
"""
super().__init__()
frame = Frame(self)
frame.pack(side = LEFT, fill="both")
button = Button(frame, padx=20, pady=20, relief=FLAT, text="upload", command=self.tempFunc, bg="#47c462")
button.pack()
self.frame1 = tk.Frame(self)
self.frame1.pack(side=LEFT, fill="both")
self.frame2 = Frame(self)
self.frame2.pack(side=LEFT, fill="both")
def uploadButton(event) -> str:
"""
Uploads the file for the model to run on. Returns a string made from
the list of characters detected by the model
Args:
event : action event on the button
Returns:
str: string made up of characters detected in image
"""
filepath = filedialog.askopenfilename()
print(filepath)
try:
im = Image.open(filepath)
im.save("images/myimage.png")
handwriting_tested = Handwriting()
word = "".join(handwriting_tested.predictedChars)
return word
except OSError:
print(OSError)
def tempFunc(self):
"""
used as a temporary function to call the showImage() and showText() functions
"""
word = self.uploadButton()
self.showImage()
self.showText(word)
def showImage(self):
"""
Shows the original image, overlayed with the bounding boxes and predicted characters
"""
try:
image1 = Image.open("images/edited.png")
test = ImageTk.PhotoImage(image1)
except IOError:
print(IOError)
label1 = tk.Label(self.frame1, image=test)
label1.image = test
label1.pack()
def showText(self, word) -> None:
"""
Shows the original string and it's corrected form
Args:
word (str): the string of characters detected in the model
"""
labelTxt = ""
search = WordSearcher()
if search.binarySearchWords(word): # if word exists return true
labelTxt = word + " -> " + word
else: # else, correct it using autocorrect
spell = Speller()
corrected = spell(word)
labelTxt = word + " -> " + corrected
label = tk.Label(self.frame2, text=labelTxt, font= ('Aerial', 17))
label.pack()