-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenimi_based_poc_app.py
More file actions
241 lines (188 loc) · 9.61 KB
/
genimi_based_poc_app.py
File metadata and controls
241 lines (188 loc) · 9.61 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import tkinter as tk
import os
import sys
from tkinter import ttk
from PIL import Image, ImageTk
from utils.blood_count_analysis import open_image, analyze_image
from utils.lab_report_analysis import upload_pdf, analyze_pdf, download_sample_pdf
from tkinter import messagebox
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def verify_login(username, password, login_top_level, root):
# Dummy authentication logic (replace with your own logic)
if username == "admin" and password == "password":
login_top_level.destroy() # Close login window
root.deiconify() # Show the main window
else:
messagebox.showwarning("Login Failed", "Incorrect username or password")
def login_window(root):
"""
Creates a top-level window for the login.
Args:
root: The root window of the application.
Returns:
None
"""
# Create a top-level window for the login
login_top_level = tk.Toplevel(root)
login_top_level.title("Login")
login_top_level.geometry("300x150")
login_top_level.grab_set() # Makes the login window modal
# Username Entry
tk.Label(login_top_level, text="Username:").pack(pady=5)
username_entry = tk.Entry(login_top_level)
username_entry.pack()
# Password Entry
tk.Label(login_top_level, text="Password:").pack(pady=5)
password_entry = tk.Entry(login_top_level, show="*")
password_entry.pack()
# Login Button
login_button = tk.Button(login_top_level, text="Login", command=lambda: verify_login(username_entry.get(), password_entry.get(), login_top_level, root))
login_button.pack(pady=10)
def close_app(root):
# Implement closing application functionality
root.destroy()
def on_enter(event, widget, color):
widget.config(bg=color)
def on_leave(event, widget, color):
widget.config(bg=color)
def create_buttons_tab1(root, left_frame, button_bg, button_fg, hover_color, right_frame, right_bg_color):
"""
Create buttons for Tab 1.
Args:
root: The root window.
left_frame: The frame where the buttons will be placed.
button_bg: The background color of the buttons.
button_fg: The foreground color of the buttons.
hover_color: The color when the mouse hovers over the buttons.
right_frame: The frame where the image label will be placed.
right_bg_color: The background color of the right frame.
"""
# Styling options
button_font = ('Helvetica', 12, 'bold')
# Create a frame for the buttons
button_frame = tk.Frame(left_frame)
button_frame.pack(pady=5)
# Upload Button
upload_button = tk.Button(button_frame, text="Upload", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: open_image(image_label))
upload_button.pack(side="left", padx=5)
upload_button.bind("<Enter>", lambda e: on_enter(e, upload_button, hover_color))
upload_button.bind("<Leave>", lambda e: on_leave(e, upload_button, button_bg))
# Analyze Button
analyze_button = tk.Button(button_frame, text="Analyze", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: analyze_image(right_frame, right_bg_color))
analyze_button.pack(side="left", padx=5)
analyze_button.bind("<Enter>", lambda e: on_enter(e, analyze_button, hover_color))
analyze_button.bind("<Leave>", lambda e: on_leave(e, analyze_button, button_bg))
# Close Button
close_button = tk.Button(button_frame, text="Close", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: close_app(root))
close_button.pack(side="left", padx=5)
close_button.bind("<Enter>", lambda e: on_enter(e, close_button, hover_color))
close_button.bind("<Leave>", lambda e: on_leave(e, close_button, button_bg))
# Label for the uploaded image
image_label = tk.Label(left_frame)
image_label.pack(pady=20)
def create_buttons_tab2(root, left_frame, button_bg, button_fg, hover_color, right_frame):
"""
Create buttons for the second tab.
Args:
root (tkinter.Tk): The root window of the application.
left_frame (tkinter.Frame): The frame where the buttons will be placed.
button_bg (str): The background color of the buttons.
button_fg (str): The foreground color (text color) of the buttons.
hover_color (str): The color of the buttons when hovered.
right_frame (tkinter.Frame): The frame where the right-side content will be displayed.
"""
# Styling options
button_font = ('Helvetica', 12, 'bold')
# Create a frame for the buttons
button_frame = tk.Frame(left_frame)
button_frame.pack(pady=5)
# Upload Button
upload_button = tk.Button(button_frame, text="Upload", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: upload_pdf(right_frame))
upload_button.pack(side="left", padx=5)
upload_button.bind("<Enter>", lambda e: on_enter(e, upload_button, hover_color))
upload_button.bind("<Leave>", lambda e: on_leave(e, upload_button, button_bg))
# Analyze Button
analyze_button = tk.Button(button_frame, text="Analyze", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: analyze_pdf(left_frame))
analyze_button.pack(side="left", padx=5)
analyze_button.bind("<Enter>", lambda e: on_enter(e, analyze_button, hover_color))
analyze_button.bind("<Leave>", lambda e: on_leave(e, analyze_button, button_bg))
# Close Button
close_button = tk.Button(button_frame, text="Close", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=lambda: close_app(root))
close_button.pack(side="left", padx=5)
close_button.bind("<Enter>", lambda e: on_enter(e, close_button, hover_color))
close_button.bind("<Leave>", lambda e: on_leave(e, close_button, button_bg))
# Create a frame for the download button
download_frame = tk.Frame(left_frame)
download_frame.pack(side="bottom", pady=(0, 20)) # Pack it to the bottom of the left_frame
# Download Button
download_button = tk.Button(download_frame, text="Download Interpreted Lab Report", font=button_font, bg=button_bg, fg=button_fg, relief="raised", borderwidth=2, command=download_sample_pdf)
download_button.pack(side="bottom", padx=5) # Pack it to the bottom of download_frame
download_button.bind("<Enter>", lambda e: on_enter(e, download_button, hover_color))
download_button.bind("<Leave>", lambda e: on_leave(e, download_button, button_bg))
def main():
try:
root = tk.Tk()
root.title("HemoCountAI")
root.geometry("800x600")
# Initialize the login window
login_window(root)
# Create a Notebook
notebook = ttk.Notebook(root)
notebook.pack(fill='both', expand=True)
# First tab - Existing functionality
existing_tab = ttk.Frame(notebook)
notebook.add(existing_tab, text='Blood Count')
# Styling options
button_fg = '#ffffff'
hover_color = "#FFA500" #'#36648b'
right_bg_color = '#333333'
# Create a frame for the left side elements (Image and Message)
left_frame = tk.Frame(existing_tab)
left_frame.pack(side="left", fill="both", expand=True)
# Create a frame for the right side elements (Logo and Buttons)
right_frame = tk.Frame(existing_tab, bg=right_bg_color)
right_frame.pack(side="right", fill="both", expand=True)
# Get the dominant color from the logo
#dominant_color = get_dominant_color(logo_path)
button_bg = "#FFA500" #'#36648b' #'#{:02x}{:02x}{:02x}'.format(*dominant_color) # Convert RGB to hex
# Load the logo
logo_image = Image.open(resource_path("logo.png"))
logo_image.thumbnail((200, 200)) # Resize if necessary
logo_photo = ImageTk.PhotoImage(logo_image)
# Display the logo
logo_label = tk.Label(left_frame, image=logo_photo)
logo_label.image = logo_photo
logo_label.pack(pady=10)
# Label for the final message
message_label = tk.Label(left_frame, text="Upload a thin blood smear image to count the number of blood cells")
message_label.pack(pady=10)
# Create buttons for the first tab
create_buttons_tab1(root, left_frame, button_bg, button_fg, hover_color, right_frame, right_bg_color)
# Second tab - Exactly like the first tab
existing_tab_2 = ttk.Frame(notebook)
notebook.add(existing_tab_2, text='Lab Report')
# Create a frame for the left side elements (Image and Message)
left_frame_2 = tk.Frame(existing_tab_2)
left_frame_2.pack(side="left", fill="both", expand=True)
# Create a frame for the right side elements (Logo and Buttons)
right_frame_2 = tk.Frame(existing_tab_2, bg=right_bg_color)
right_frame_2.pack(side="right", fill="both", expand=True)
# Display the logo
logo_label_2 = tk.Label(left_frame_2, image=logo_photo)
logo_label_2.image = logo_photo
logo_label_2.pack(pady=10)
# Label for the final message
message_label_2 = tk.Label(left_frame_2, text="Upload a pdf of lab report to analyze")
message_label_2.pack(pady=5)
# Create buttons for the second tab
create_buttons_tab2(root, left_frame_2, button_bg, button_fg, hover_color, right_frame_2)
root.mainloop()
except Exception as e:
messagebox.showwarning("Error", f"An error occurred: {e}")
if __name__ == "__main__":
main()