-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__main__.py
155 lines (131 loc) · 5.41 KB
/
__main__.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
import tkinter as tk
from tkinter import filedialog
from PIL import ImageTk, Image
import time
class Public_Variable_Storage():
def __init__(self):
self.img_path = None
self.final_char = None
self.algorithm = None
self.timing = None
def setImgPath(self, fpath):
self.path = fpath
def getImgPath(self):
return self.path
def setFinalChar(self, fChar):
self.final_char = fChar
def getFinalChar(self):
return self.final_char
def setAlgorithm(self, algor):
self.algorithm = algor
def getAlgorithm(self):
return self.algorithm
def setTime(self, t):
self.timing = str(t)
def getTime(self):
return self.timing
public = Public_Variable_Storage()
login = tk.Tk()
loginframe = tk.Frame(login)
login.title("Welcome to Apples-to-Oranges! ")
tk.Label(login, text="Hello! This program takes in a picture and decides whether the picture looks").grid()
tk.Label(login, text="more like an apple or an orange based on the colors presented in the image.").grid()
def final_verdict():
algo.destroy()
verdict = tk.Tk()
vFrame = tk.Frame(verdict)
verdict.title("Is it an apple or an orange?")
tk.Label(verdict, text="Your image is an...").grid()
if public.getFinalChar() == "o":
f = "Orange!"
col = "orange"
elif public.getFinalChar() == "a":
f = "Apple!"
col = "red"
else:
f = "Undecided! The program could not comprehend your image."
col = "blue"
tk.Label(verdict, text=f, fg=col, font=('Comic Sans MS',30)).grid()
tk.Label(verdict, text="Using a " + public.getAlgorithm() + " algorithm, the program").grid()
tk.Label(verdict, text="trained and tested data to come up with an answer in").grid()
tk.Label(verdict, text=str(public.getTime()) + " seconds!").grid()
tk.Button(verdict, text="Exit", command=exit).grid()
def chooseAlgorithm():
login.destroy()
global algo
algo = tk.Tk()
algoframe = tk.Frame(algo)
algo.title("Choose an Algorithm")
tk.Label(algo, text="Please choose an algorithm for the AI to use! More will be added!")
def decision_tree():
public.setAlgorithm("Decision Tree")
tk.Label(algo, text="Loading... Please Wait...").grid()
time.sleep(2)
from algorithms import decision_tree
ans = decision_tree.answer(public.getImgPath())
public.setFinalChar(ans[0])
public.setTime(ans[1])
final_verdict()
def kn_neighbors():
public.setAlgorithm("K-Nearest Neighbors")
tk.Label(algo, text="Loading... Please Wait...").grid()
time.sleep(2)
from algorithms import k_nearest_neighbors
ans = k_nearest_neighbors.answer(public.getImgPath())
public.setFinalChar(ans[0])
public.setTime(ans[1])
final_verdict()
def log_regression():
public.setAlgorithm("Logistic Regression")
tk.Label(algo, text="Loading... Please Wait...").grid()
time.sleep(2)
from algorithms import logistic_regression
ans = logistic_regression.answer(public.getImgPath())
public.setFinalChar(ans[0])
public.setTime(ans[1])
final_verdict()
def neural_net():
public.setAlgorithm("Neural Network")
tk.Label(algo, text="Loading... Please Wait...").grid()
time.sleep(2)
from algorithms import neural_network
ans = neural_network.answer(public.getImgPath())
public.setFinalChar(ans[0])
public.setTime(ans[1])
final_verdict()
def k_means():
public.setAlgorithm("K-Means Clustering")
tk.Label(algo, text="Loading... Please Wait...").grid()
time.sleep(2)
from algorithms import k_means_clustering
ans = k_means_clustering.answer(public.getImgPath())
public.setFinalChar(ans[0])
public.setTime(ans[1])
final_verdict()
tk.Button(algo, text="Decision Tree", command=decision_tree).grid()
tk.Button(algo, text="K-Nearest Neighbors", command=kn_neighbors).grid()
tk.Button(algo, text="Logistic Regression", command=log_regression).grid()
tk.Button(algo, text="Neural Network", command=neural_net).grid()
tk.Button(algo, text="K-Means Clustering", command=k_means).grid()
algo.mainloop()
def getImage():
public.setImgPath(filedialog.askopenfilename(initialdir = "/",title = "Please select a picture of an apple, orange, or whatever! Make sure its a JPG, JPEG, or PNG file.")) # File must be a .jpg or .jpeg
if public.getImgPath():
confirm = tk.Toplevel()
confirmframe = tk.Frame(confirm)
confirm.title("This is your picture?")
tk.Label(confirm, text="Is this the picture that you want to use?").grid()
img = ImageTk.PhotoImage(Image.open(public.getImgPath()).resize((300, 300), Image.ANTIALIAS))
tk.Label(confirm, image=img, height=200).grid()
def yes():
confirm.destroy()
tk.Button(login, text="Choose ML Algorithm to parse data.", command=chooseAlgorithm).grid()
def no():
confirm.destroy()
getImage()
tk.Button(confirm, text="Yes", command=yes).grid(row=1, column=1)
tk.Button(confirm, text = "No", command=no).grid(row=1, column=2)
confirm.mainloop()
tk.Button(login, text="Choose image to have the AI process", command=getImage).grid()
tk.Button(login, text="Exit", command=login.destroy).grid()
login.mainloop()