-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
1359 lines (1107 loc) Β· 54.1 KB
/
Copy pathgui.py
File metadata and controls
1359 lines (1107 loc) Β· 54.1 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
MedAI GUI - Modern Medical Report Analysis Interface
Built with CustomTkinter for a professional, modern design
"""
import customtkinter as ctk
from tkinter import filedialog, messagebox
import threading
import os
from pathlib import Path
import json
from datetime import datetime
import tkinter as tk
import numpy as np
from main import MedAI
# Set appearance mode and color theme
ctk.set_appearance_mode("light") # "light" or "dark"
ctk.set_default_color_theme("blue") # "blue", "green", "dark-blue"
class MedAIModernGUI:
def __init__(self):
# Create main window with enhanced settings
self.root = ctk.CTk()
self.root.title("MedAI - Advanced Medical Report Analysis by Dielldev")
self.root.geometry("1450x950")
self.root.minsize(1300, 850)
# Set window properties
self.root.resizable(True, True)
# Try to set window icon (optional - will fail gracefully if icon not found)
try:
self.root.iconbitmap("icon.ico") # Add if you have an icon file
except:
pass # Continue without icon if not found
# Initialize variables
self.medai = None
self.current_results = None
self.selected_file = None
# Create the modern interface
self.create_widgets()
# Load MedAI in background
self.load_medai_async()
def darken_color(self, color):
"""Helper method to darken a color for hover effects"""
color_map = {
"#3498db": "#2980b9",
"#e74c3c": "#c0392b",
"#2ecc71": "#27ae60",
"#9b59b6": "#8e44ad"
}
return color_map.get(color, color)
def create_widgets(self):
"""Create the modern UI layout"""
# Configure grid layout
self.root.grid_columnconfigure(1, weight=1)
self.root.grid_rowconfigure(0, weight=1)
# Create sidebar
self.create_sidebar()
# Create main content area
self.create_main_content()
# Show welcome screen
self.show_welcome_screen()
def create_sidebar(self):
"""Create the left sidebar with controls"""
# Sidebar frame with improved styling
self.sidebar_frame = ctk.CTkFrame(self.root, width=380, corner_radius=15)
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew", padx=(15, 8), pady=15)
self.sidebar_frame.grid_rowconfigure(10, weight=1)
# Header section with enhanced styling
self.header_frame = ctk.CTkFrame(self.sidebar_frame, fg_color="transparent")
self.header_frame.grid(row=0, column=0, sticky="ew", padx=0, pady=(20, 15))
# Title and logo with gradient-like effect
self.logo_label = ctk.CTkLabel(
self.header_frame,
text="π₯ MedAI",
font=ctk.CTkFont(size=32, weight="bold"),
text_color=("#1f4e79", "#4a90e2")
)
self.logo_label.pack(pady=(0, 2))
self.subtitle_label = ctk.CTkLabel(
self.header_frame,
text="Advanced Medical Report Analysis",
font=ctk.CTkFont(size=13, weight="normal"),
text_color=("gray50", "gray70")
)
self.subtitle_label.pack(pady=(0, 5))
# Add a subtle divider
self.divider_frame = ctk.CTkFrame(self.header_frame, height=2, fg_color=("gray80", "gray30"))
self.divider_frame.pack(fill="x", padx=40, pady=(10, 0))
# File Selection Section with improved spacing
self.file_section_frame = ctk.CTkFrame(self.sidebar_frame, fg_color="transparent")
self.file_section_frame.grid(row=1, column=0, sticky="ew", padx=20, pady=(20, 10))
self.file_section_label = ctk.CTkLabel(
self.file_section_frame,
text="π File Analysis",
font=ctk.CTkFont(size=17, weight="bold"),
anchor="w"
)
self.file_section_label.pack(anchor="w", pady=(0, 8))
# File selection button with improved styling
self.select_file_btn = ctk.CTkButton(
self.file_section_frame,
text="π Browse Medical Reports",
command=self.select_file,
height=45,
font=ctk.CTkFont(size=14, weight="bold"),
corner_radius=12,
fg_color=("#3498db", "#2980b9"),
hover_color=("#2980b9", "#1f618d")
)
self.select_file_btn.pack(fill="x", pady=(0, 8))
# Selected file display with better styling
self.file_display_frame = ctk.CTkFrame(self.file_section_frame, corner_radius=8, fg_color=("gray92", "gray20"))
self.file_display_frame.pack(fill="x", pady=(0, 10))
self.file_path_var = tk.StringVar(value="No file selected")
self.file_path_label = ctk.CTkLabel(
self.file_display_frame,
textvariable=self.file_path_var,
wraplength=320,
font=ctk.CTkFont(size=11),
text_color=("gray40", "gray80"),
justify="left"
)
self.file_path_label.pack(padx=12, pady=8)
# Analyze button with prominent styling
self.analyze_btn = ctk.CTkButton(
self.file_section_frame,
text="π Analyze Report",
command=self.analyze_report,
height=50,
font=ctk.CTkFont(size=16, weight="bold"),
corner_radius=15,
fg_color=("#27ae60", "#2ecc71"),
hover_color=("#229954", "#27ae60"),
state="disabled"
)
self.analyze_btn.pack(fill="x", pady=(5, 0))
# Language selection with improved layout
self.lang_section_frame = ctk.CTkFrame(self.sidebar_frame, fg_color="transparent")
self.lang_section_frame.grid(row=2, column=0, sticky="ew", padx=20, pady=(15, 10))
self.lang_section_label = ctk.CTkLabel(
self.lang_section_frame,
text="π Language Settings",
font=ctk.CTkFont(size=17, weight="bold"),
anchor="w"
)
self.lang_section_label.pack(anchor="w", pady=(0, 8))
self.language_var = tk.StringVar(value="English + Albanian")
self.language_menu = ctk.CTkOptionMenu(
self.lang_section_frame,
values=["English + Albanian", "English", "Albanian"],
variable=self.language_var,
command=self.on_language_change,
font=ctk.CTkFont(size=13),
corner_radius=10,
height=40
)
self.language_menu.pack(fill="x")
# Text Analysis Section with enhanced styling
self.text_section_frame = ctk.CTkFrame(self.sidebar_frame, fg_color="transparent")
self.text_section_frame.grid(row=3, column=0, sticky="ew", padx=20, pady=(20, 10))
self.text_section_label = ctk.CTkLabel(
self.text_section_frame,
text="π Direct Text Analysis",
font=ctk.CTkFont(size=17, weight="bold"),
anchor="w"
)
self.text_section_label.pack(anchor="w", pady=(0, 8))
# Text input with placeholder styling
self.text_input_frame = ctk.CTkFrame(self.text_section_frame, corner_radius=12)
self.text_input_frame.pack(fill="x", pady=(0, 10))
self.text_input = ctk.CTkTextbox(
self.text_input_frame,
height=140,
font=ctk.CTkFont(size=12),
wrap="word",
corner_radius=8
)
self.text_input.pack(fill="both", expand=True, padx=8, pady=8)
self.text_input.insert("0.0", "Paste your medical report text here...")
# Analyze text button with distinct styling
self.analyze_text_btn = ctk.CTkButton(
self.text_section_frame,
text="π Analyze Text",
command=self.analyze_text,
height=45,
font=ctk.CTkFont(size=14, weight="bold"),
corner_radius=12,
fg_color=("#e74c3c", "#c0392b"),
hover_color=("#c0392b", "#a93226")
)
self.analyze_text_btn.pack(fill="x")
# Status and Database Section with refined design
self.status_section_frame = ctk.CTkFrame(self.sidebar_frame, fg_color="transparent")
self.status_section_frame.grid(row=4, column=0, sticky="ew", padx=20, pady=(25, 15))
# Status card with elegant design
self.status_frame = ctk.CTkFrame(self.status_section_frame, corner_radius=15, fg_color=("gray96", "gray17"))
self.status_frame.pack(fill="x")
# Status header
self.status_header = ctk.CTkLabel(
self.status_frame,
text="β‘ System Status",
font=ctk.CTkFont(size=15, weight="bold"),
anchor="w"
)
self.status_header.pack(anchor="w", padx=15, pady=(15, 5))
# Progress label with better styling
self.progress_var = tk.StringVar(value="Initializing MedAI...")
self.progress_label = ctk.CTkLabel(
self.status_frame,
textvariable=self.progress_var,
font=ctk.CTkFont(size=12, weight="bold"),
text_color=("#2c3e50", "#ecf0f1")
)
self.progress_label.pack(anchor="w", padx=15, pady=(0, 8))
# Progress bar with custom styling
self.progress_bar = ctk.CTkProgressBar(
self.status_frame,
mode="indeterminate",
corner_radius=10,
height=8
)
self.progress_bar.pack(fill="x", padx=15, pady=(0, 12))
self.progress_bar.start()
# Case count with icon
self.case_count_var = tk.StringVar(value="π Cases: Loading...")
self.case_count_label = ctk.CTkLabel(
self.status_frame,
textvariable=self.case_count_var,
font=ctk.CTkFont(size=12),
text_color=("gray30", "gray80")
)
self.case_count_label.pack(anchor="w", padx=15, pady=(0, 10))
# Action buttons with improved layout
self.action_buttons_frame = ctk.CTkFrame(self.status_frame, fg_color="transparent")
self.action_buttons_frame.pack(fill="x", padx=15, pady=(0, 15))
# View cases button
self.view_cases_btn = ctk.CTkButton(
self.action_buttons_frame,
text="ποΈ View Database",
command=self.view_cases,
height=38,
font=ctk.CTkFont(size=12, weight="bold"),
corner_radius=10,
fg_color=("#9b59b6", "#8e44ad"),
hover_color=("#8e44ad", "#7d3c98")
)
self.view_cases_btn.pack(fill="x")
def create_main_content(self):
"""Create the main content area for results"""
# Main content frame with enhanced styling
self.main_frame = ctk.CTkFrame(self.root, corner_radius=15)
self.main_frame.grid(row=0, column=1, sticky="nsew", padx=(8, 15), pady=15)
self.main_frame.grid_columnconfigure(0, weight=1)
self.main_frame.grid_rowconfigure(2, weight=1)
# --- Results Header (Initially Hidden) ---
self.results_header_frame = ctk.CTkFrame(self.main_frame, fg_color="transparent")
self.results_header_frame.grid_columnconfigure(1, weight=1)
# Header card with gradient-like styling
self.header_card = ctk.CTkFrame(self.results_header_frame, corner_radius=12, fg_color=("gray97", "gray15"))
self.header_card.grid(row=0, column=0, columnspan=2, sticky="ew", padx=15, pady=(15, 10))
self.header_card.grid_columnconfigure(0, weight=1)
self.diagnosis_header_label = ctk.CTkLabel(
self.header_card,
text="",
font=ctk.CTkFont(size=26, weight="bold"),
text_color=("#1a365d", "#90cdf4")
)
self.diagnosis_header_label.grid(row=0, column=0, sticky="w", padx=20, pady=(15, 5))
self.confidence_header_label = ctk.CTkLabel(
self.header_card,
text="",
font=ctk.CTkFont(size=14),
text_color=("gray50", "gray70")
)
self.confidence_header_label.grid(row=1, column=0, sticky="w", padx=20, pady=(0, 15))
# --- Enhanced Navigation Buttons ---
self.nav_frame = ctk.CTkFrame(self.main_frame, fg_color="transparent")
self.nav_frame.grid_columnconfigure((0, 1, 2, 3), weight=1)
self.nav_buttons = {}
nav_items = [
("π Summary", "#3498db"),
("π©Ί Medical Data", "#e74c3c"),
("π¬ Diagnosis", "#2ecc71"),
("π Similar Cases", "#9b59b6")
]
for i, (item, color) in enumerate(nav_items):
btn = ctk.CTkButton(
self.nav_frame,
text=item,
font=ctk.CTkFont(size=14, weight="bold"),
command=lambda view=item: self.switch_view(view),
corner_radius=12,
height=45,
fg_color=color,
hover_color=self.darken_color(color),
text_color=("white", "white") # Ensure text is always visible
)
btn.grid(row=0, column=i, padx=8, pady=8, sticky="ew")
self.nav_buttons[item] = btn
# --- Enhanced Content Frames ---
self.content_frame = ctk.CTkFrame(self.main_frame, fg_color="transparent")
self.content_frame.grid(row=2, column=0, sticky="nsew", padx=15, pady=15)
self.content_frame.grid_rowconfigure(0, weight=1)
self.content_frame.grid_columnconfigure(0, weight=1)
self.content_frames = {}
nav_item_names = ["π Summary", "π©Ί Medical Data", "π¬ Diagnosis", "π Similar Cases"]
for view in nav_item_names:
frame = ctk.CTkFrame(self.content_frame, corner_radius=12, fg_color=("gray98", "gray14"))
frame.grid(row=0, column=0, sticky="nsew")
self.content_frames[view] = frame
frame.grid_remove() # Hide all frames initially
# --- Populate Content Frames with improved styling ---
# Summary tab with enhanced text area
self.summary_textbox = ctk.CTkTextbox(
self.content_frames["π Summary"],
font=ctk.CTkFont(family="Segoe UI", size=13),
wrap="word",
corner_radius=8
)
self.summary_textbox.pack(fill="both", expand=True, padx=12, pady=12)
# Medical Data tab
self.create_medical_data_tab()
# Diagnosis tab with enhanced styling
self.diagnosis_textbox = ctk.CTkTextbox(
self.content_frames["π¬ Diagnosis"],
font=ctk.CTkFont(family="Segoe UI", size=13),
wrap="word",
corner_radius=8
)
self.diagnosis_textbox.pack(fill="both", expand=True, padx=12, pady=12)
# Similar Cases tab with enhanced styling
self.cases_textbox = ctk.CTkTextbox(
self.content_frames["π Similar Cases"],
font=ctk.CTkFont(family="Segoe UI", size=12),
wrap="word",
corner_radius=8
)
self.cases_textbox.pack(fill="both", expand=True, padx=12, pady=12)
# --- Enhanced Export Buttons ---
self.export_frame = ctk.CTkFrame(self.main_frame, fg_color="transparent")
self.export_frame.grid_columnconfigure((0, 1), weight=1)
self.export_summary_btn = ctk.CTkButton(
self.export_frame,
text="π Export Summary",
command=self.export_summary,
font=ctk.CTkFont(size=13, weight="bold"),
corner_radius=12,
height=42,
fg_color=("#27ae60", "#2ecc71"),
hover_color=("#229954", "#27ae60")
)
self.export_summary_btn.grid(row=0, column=0, padx=(15, 8), pady=12, sticky="ew")
self.export_full_btn = ctk.CTkButton(
self.export_frame,
text="π Export Full Report",
command=self.export_full_report,
font=ctk.CTkFont(size=13, weight="bold"),
corner_radius=12,
height=42,
fg_color=("#8e44ad", "#9b59b6"),
hover_color=("#7d3c98", "#8e44ad")
)
self.export_full_btn.grid(row=0, column=1, padx=(8, 15), pady=12, sticky="ew")
# --- Enhanced Welcome Screen ---
self.welcome_container = ctk.CTkFrame(self.main_frame, corner_radius=15, fg_color=("gray98", "gray14"))
self.welcome_container.grid(row=0, column=0, rowspan=4, sticky="nsew", padx=15, pady=15)
self.welcome_container.grid_columnconfigure(0, weight=1)
self.welcome_container.grid_rowconfigure(1, weight=1)
# Welcome header
self.welcome_header_frame = ctk.CTkFrame(self.welcome_container, fg_color="transparent")
self.welcome_header_frame.grid(row=0, column=0, sticky="ew", padx=30, pady=(30, 15))
self.welcome_title = ctk.CTkLabel(
self.welcome_header_frame,
text="π₯ Medical Report Analysis",
font=ctk.CTkFont(size=28, weight="bold"),
text_color=("#1a365d", "#90cdf4")
)
self.welcome_title.pack()
self.welcome_subtitle = ctk.CTkLabel(
self.welcome_header_frame,
text="Advanced AI-Powered Medical Intelligence",
font=ctk.CTkFont(size=14),
text_color=("gray50", "gray70")
)
self.welcome_subtitle.pack(pady=(5, 0))
# Welcome content area
self.welcome_content = ctk.CTkTextbox(
self.welcome_container,
font=ctk.CTkFont(family="Segoe UI", size=13),
wrap="word",
corner_radius=8
)
self.welcome_content.grid(row=1, column=0, sticky="nsew", padx=20, pady=(0, 30))
self.show_welcome_screen()
def switch_view(self, view_name):
"""Switch between content views"""
for view, frame in self.content_frames.items():
if view == view_name:
frame.grid()
else:
frame.grid_remove()
# Update button appearance - highlight selected button
for name, btn in self.nav_buttons.items():
if name == view_name:
# Make selected button darker and more prominent
original_color = {
"π Summary": "#2980b9",
"π©Ί Medical Data": "#c0392b",
"π¬ Diagnosis": "#27ae60",
"π Similar Cases": "#8e44ad"
}
btn.configure(fg_color=original_color.get(name, "#2980b9"))
else:
# Keep unselected buttons with their original colors but slightly lighter
original_color = {
"π Summary": "#3498db",
"π©Ί Medical Data": "#e74c3c",
"π¬ Diagnosis": "#2ecc71",
"π Similar Cases": "#9b59b6"
}
btn.configure(fg_color=original_color.get(name, "#3498db"))
def create_medical_data_tab(self):
"""Create the medical data tab with scrollable frame"""
# Create scrollable frame for medical data with enhanced styling
self.medical_data_frame = ctk.CTkScrollableFrame(
self.content_frames["π©Ί Medical Data"],
corner_radius=8,
fg_color="transparent"
)
self.medical_data_frame.pack(fill="both", expand=True, padx=12, pady=12)
# Header for medical data with improved styling
self.medical_data_header_frame = ctk.CTkFrame(self.medical_data_frame, fg_color="transparent")
self.medical_data_header_frame.pack(fill="x", pady=(0, 15))
self.medical_data_header = ctk.CTkLabel(
self.medical_data_header_frame,
text="π Extracted Medical Parameters",
font=ctk.CTkFont(size=20, weight="bold"),
text_color=("#2c3e50", "#ecf0f1"),
anchor="w"
)
self.medical_data_header.pack(anchor="w")
self.medical_data_subtitle = ctk.CTkLabel(
self.medical_data_header_frame,
text="Organized analysis of medical values with status indicators",
font=ctk.CTkFont(size=12),
text_color=("gray50", "gray70"),
anchor="w"
)
self.medical_data_subtitle.pack(anchor="w", pady=(2, 0))
# This will be populated with medical data cards
self.medical_data_cards = []
def show_welcome_screen(self):
"""Show welcome message in the main area"""
# Ensure results UI is hidden
self.results_header_frame.grid_remove()
self.nav_frame.grid_remove()
self.content_frame.grid_remove()
self.export_frame.grid_remove()
# Show welcome container
self.welcome_container.grid()
welcome_text = """
π Welcome to MedAI - Next-Generation Medical Analysis
Experience the future of medical report processing with our advanced AI-powered platform.
β¨ CUTTING-EDGE FEATURES:
π¬ Advanced OCR Technology
β’ Extract text from PDFs, images, and scanned documents
β’ Support for multiple image formats (JPG, PNG, TIFF, BMP)
β’ High-precision medical text recognition
π§ Intelligent AI Analysis
β’ Deep learning models for medical data extraction
β’ Pattern recognition for symptom identification
β’ Predictive diagnosis with confidence scoring
π Smart Case Matching
β’ Semantic similarity analysis
β’ Historical case database integration
β’ Pattern-based diagnostic suggestions
π Comprehensive Reporting
β’ Detailed medical parameter extraction
β’ Professional analysis summaries
β’ Exportable reports in multiple formats
οΏ½ GETTING STARTED:
π FILE ANALYSIS METHOD:
1. Click "Browse Medical Reports" to select your document
2. Choose from PDF, JPG, PNG, TIFF, or BMP formats
3. Click "Analyze Report" to process with OCR + AI
4. View results across multiple organized tabs
π DIRECT TEXT METHOD:
1. Paste medical report text in the left sidebar
2. Click "Analyze Text" for immediate processing
3. Perfect for pre-extracted or typed content
4. Instant analysis without file upload
π LANGUAGE SUPPORT:
β’ English - Full medical terminology support
β’ Albanian - Comprehensive medical vocabulary
β’ Bilingual - Process mixed-language documents
π PRIVACY & SECURITY GUARANTEED:
β
100% local processing - No cloud uploads
β
Your data never leaves your device
β
HIPAA-compliant by design
β
Enterprise-grade privacy protection
π ANALYSIS RESULTS INCLUDE:
β’ Extracted medical parameters with normal ranges
β’ AI-powered diagnostic predictions
β’ Confidence levels and supporting evidence
β’ Similar case matches from your database
β’ Comprehensive summary reports
β οΈ MEDICAL DISCLAIMER:
This advanced tool is designed for educational, research, and clinical decision support purposes.
Always consult qualified healthcare professionals for medical decisions and final diagnosis.
The AI predictions are meant to assist, not replace, professional medical judgment.
π― Ready to revolutionize your medical analysis workflow!
"""
self.welcome_content.delete("0.0", "end")
self.welcome_content.insert("0.0", welcome_text)
def change_appearance_mode_event(self, new_appearance_mode: str):
"""Change the appearance mode"""
ctk.set_appearance_mode(new_appearance_mode.lower())
def on_language_change(self, choice):
"""Handle language selection change"""
lang_map = {
"English + Albanian": ['eng', 'sqi'],
"English": ['eng'],
"Albanian": ['sqi']
}
selected_langs = lang_map.get(choice, ['eng', 'sqi'])
# Re-load MedAI with new languages
self.load_medai_async(languages=selected_langs)
def load_medai_async(self, languages=['eng', 'sqi']):
"""Load MedAI in background thread with specified languages"""
def load():
try:
self.root.after(0, lambda: self.progress_var.set("Loading AI models..."))
self.root.after(0, lambda: self.progress_bar.start())
from main import MedAI
self.medai = MedAI(languages=languages)
# Update UI on main thread
self.root.after(0, self.on_medai_loaded)
except Exception as e:
self.root.after(0, lambda: self.on_medai_error(str(e)))
thread = threading.Thread(target=load, daemon=True)
thread.start()
def on_medai_loaded(self):
"""Called when MedAI is successfully loaded"""
self.progress_bar.stop()
self.progress_var.set("π’ System Ready")
self.case_count_var.set(f"π Cases: {len(self.medai.cases_db)}")
# Enable buttons with improved state management
self.select_file_btn.configure(state="normal")
self.analyze_text_btn.configure(state="normal")
def on_medai_error(self, error_msg):
"""Called when MedAI loading fails"""
self.progress_bar.stop()
self.progress_var.set("β System Error")
messagebox.showerror("Initialization Error", f"Failed to load MedAI: {error_msg}")
def select_file(self):
"""Open file dialog to select medical report"""
filetypes = [
("All Supported", "*.pdf *.jpg *.jpeg *.png *.bmp *.tiff"),
("PDF files", "*.pdf"),
("Image files", "*.jpg *.jpeg *.png *.bmp *.tiff"),
("All files", "*.*")
]
filename = filedialog.askopenfilename(
title="Select Medical Report",
filetypes=filetypes
)
if filename:
self.selected_file = filename
file_name = Path(filename).name
# Truncate long filenames for better display
display_name = file_name if len(file_name) <= 35 else file_name[:32] + "..."
self.file_path_var.set(f"π {display_name}")
self.analyze_btn.configure(state="normal")
def analyze_report(self):
"""Analyze the selected medical report file"""
if not self.selected_file:
messagebox.showwarning("No File Selected", "Please select a medical report file first.")
return
if not self.medai:
messagebox.showwarning("System Not Ready", "MedAI is still loading. Please wait.")
return
def analyze():
try:
# Update UI
self.root.after(0, lambda: self.progress_var.set("π Analyzing report..."))
self.root.after(0, lambda: self.progress_bar.start())
# Run analysis
results = self.medai.analyze_report(self.selected_file)
# Update UI with results
self.root.after(0, lambda: self.progress_bar.stop())
if 'error' in results:
self.root.after(0, lambda: self.progress_var.set("β Analysis failed"))
self.root.after(0, lambda: messagebox.showerror("Analysis Error", results['error']))
else:
self.root.after(0, lambda: self.progress_var.set("β
Analysis complete"))
self.current_results = results
self.root.after(0, lambda: self.display_results(results))
self.root.after(0, lambda: self.case_count_var.set(f"Cases: {len(self.medai.cases_db)}"))
except Exception as e:
self.root.after(0, lambda: self.progress_bar.stop())
self.root.after(0, lambda: self.progress_var.set("β Error"))
self.root.after(0, lambda: messagebox.showerror("Analysis Error", f"Failed to analyze: {str(e)}"))
thread = threading.Thread(target=analyze, daemon=True)
thread.start()
def analyze_text(self):
"""Analyze text input directly"""
text = self.text_input.get("0.0", "end").strip()
# Remove placeholder text
if text == "Paste your medical report text here...":
text = ""
if not text:
messagebox.showwarning("No Text Entered", "Please enter medical report text to analyze.")
return
if not self.medai:
messagebox.showwarning("System Not Ready", "MedAI is still loading. Please wait.")
return
def analyze():
try:
# Update UI
self.root.after(0, lambda: self.progress_var.set("π Analyzing text..."))
self.root.after(0, lambda: self.progress_bar.start())
# Parse medical values
medical_data = self.medai.parse_medical_values(text)
# Generate embeddings
embedding = self.medai.generate_embeddings(text)
# Find similar cases
similar_cases = self.medai.find_similar_cases(embedding)
# Predict diagnosis
prediction = self.medai.predict_diagnosis(medical_data, similar_cases)
# Generate summary
summary = self.medai.generate_summary(medical_data, prediction, similar_cases)
# Save case
self.medai.save_case(text, medical_data, prediction, embedding)
self.medai.save_data()
# Create results
results = {
'extracted_text': text,
'medical_data': medical_data,
'prediction': prediction,
'similar_cases': similar_cases,
'summary': summary
}
# Update UI
self.root.after(0, lambda: self.progress_bar.stop())
self.root.after(0, lambda: self.progress_var.set("β
Analysis complete"))
self.current_results = results
self.root.after(0, lambda: self.display_results(results))
self.root.after(0, lambda: self.case_count_var.set(f"Cases: {len(self.medai.cases_db)}"))
except Exception as e:
self.root.after(0, lambda: self.progress_bar.stop())
self.root.after(0, lambda: self.progress_var.set("β Error"))
self.root.after(0, lambda: messagebox.showerror("Analysis Error", f"Text analysis failed: {str(e)}"))
thread = threading.Thread(target=analyze, daemon=True)
thread.start()
def display_results(self, results):
"""Display analysis results in the modern GUI"""
# Hide welcome screen, show results UI
self.welcome_container.grid_remove()
self.results_header_frame.grid(row=0, column=0, sticky="ew", padx=0, pady=0)
self.nav_frame.grid(row=1, column=0, sticky="ew", padx=15, pady=(10, 0))
self.content_frame.grid(row=2, column=0, sticky="nsew", padx=0, pady=0)
self.export_frame.grid(row=3, column=0, sticky="ew", padx=0, pady=0)
# --- Populate Header ---
primary_diagnosis = results['prediction']['primary_diagnosis'].replace('_', ' ').title()
confidence = results['prediction']['confidence']
self.diagnosis_header_label.configure(text=f"π¬ {primary_diagnosis}")
self.confidence_header_label.configure(text=f"Confidence: {confidence:.0%} β’ Analysis completed successfully")
# --- Populate Content ---
# Summary tab
self.summary_textbox.delete("0.0", "end")
self.summary_textbox.insert("0.0", results['summary'])
# Medical Data tab
self.display_medical_data_cards(results['medical_data'])
# Diagnosis tab
self.display_diagnosis_details(results['prediction'], results['medical_data'])
# Similar Cases tab
self.display_similar_cases(results['similar_cases'])
# Switch to summary view by default
self.switch_view("π Summary")
def display_medical_data_cards(self, medical_data):
"""Display medical data as modern cards"""
# Clear existing cards
for card in self.medical_data_cards:
card.destroy()
self.medical_data_cards.clear()
if not medical_data:
# Enhanced no data display
no_data_frame = ctk.CTkFrame(
self.medical_data_frame,
corner_radius=15,
fg_color=("gray95", "gray20")
)
no_data_frame.pack(fill="x", padx=5, pady=20)
no_data_icon = ctk.CTkLabel(
no_data_frame,
text="π",
font=ctk.CTkFont(size=48)
)
no_data_icon.pack(pady=(30, 10))
no_data_label = ctk.CTkLabel(
no_data_frame,
text="No Medical Data Extracted",
font=ctk.CTkFont(size=18, weight="bold"),
text_color=("gray40", "gray80")
)
no_data_label.pack(pady=(0, 10))
no_data_subtitle = ctk.CTkLabel(
no_data_frame,
text="The document may not contain structured medical parameters\nor the values could not be automatically detected.",
font=ctk.CTkFont(size=12),
text_color=("gray50", "gray70"),
justify="center"
)
no_data_subtitle.pack(pady=(0, 30))
self.medical_data_cards.append(no_data_frame)
return
# Create cards for each medical parameter
for i, (key, value) in enumerate(medical_data.items()):
self.create_medical_data_card(key, value, i)
def create_medical_data_card(self, key, value, index):
"""Create a modern card for medical data"""
# Format the parameter name
param_name = key.replace('_', ' ').title()
# Get appropriate color and icon based on parameter type
color_info = self.get_parameter_color_and_icon(key, value)
# Create card frame with enhanced styling
card_frame = ctk.CTkFrame(
self.medical_data_frame,
corner_radius=15,
fg_color=color_info['bg_color'],
border_width=2,
border_color=("gray85", "gray25")
)
card_frame.pack(fill="x", padx=5, pady=12)
# Configure grid with better proportions
card_frame.grid_columnconfigure(1, weight=1)
# Icon/Emoji with enhanced styling
icon_frame = ctk.CTkFrame(card_frame, fg_color="transparent", width=60)
icon_frame.grid(row=0, column=0, rowspan=2, padx=20, pady=20, sticky="ns")
icon_label = ctk.CTkLabel(
icon_frame,
text=color_info['icon'],
font=ctk.CTkFont(size=28)
)
icon_label.pack(expand=True)
# Parameter name with improved styling
name_label = ctk.CTkLabel(
card_frame,
text=param_name,
font=ctk.CTkFont(size=18, weight="bold"),
text_color=color_info['text_color'],
anchor="w"
)
name_label.grid(row=0, column=1, sticky="w", padx=15, pady=(20, 5))
# Value and unit with enhanced presentation
unit = self.get_unit_for_parameter(key)
value_text = f"{value} {unit}".strip()
value_label = ctk.CTkLabel(
card_frame,
text=value_text,
font=ctk.CTkFont(size=16, weight="bold"),
text_color=color_info['value_color'],
anchor="w"
)
value_label.grid(row=1, column=1, sticky="w", padx=15, pady=(0, 20))
# Status indicator with enhanced styling
status = self.get_parameter_status(key, value)
if status:
status_frame = ctk.CTkFrame(card_frame, fg_color="transparent")
status_frame.grid(row=0, column=2, rowspan=2, padx=20, pady=20, sticky="ns")
status_label = ctk.CTkLabel(
status_frame,
text=status['text'],
font=ctk.CTkFont(size=14, weight="bold"),
text_color=status['color']
)
status_label.pack(expand=True)
self.medical_data_cards.append(card_frame)
def get_parameter_color_and_icon(self, key, value):
"""Get color scheme and icon for medical parameter"""
color_schemes = {
'blood_pressure': {'icon': 'π«', 'bg_color': '#ffebee', 'text_color': '#c62828', 'value_color': '#d32f2f'},
'systolic_bp': {'icon': 'π', 'bg_color': '#ffebee', 'text_color': '#c62828', 'value_color': '#d32f2f'},
'diastolic_bp': {'icon': 'π', 'bg_color': '#ffebee', 'text_color': '#c62828', 'value_color': '#d32f2f'},
'heart_rate': {'icon': 'π', 'bg_color': '#f3e5f5', 'text_color': '#7b1fa2', 'value_color': '#8e24aa'},
'temperature': {'icon': 'π‘οΈ', 'bg_color': '#fff3e0', 'text_color': '#e65100', 'value_color': '#f57c00'},
'glucose': {'icon': 'π―', 'bg_color': '#e8f5e8', 'text_color': '#2e7d32', 'value_color': '#388e3c'},
'weight': {'icon': 'βοΈ', 'bg_color': '#e3f2fd', 'text_color': '#1565c0', 'value_color': '#1976d2'},
'height': {'icon': 'π', 'bg_color': '#e3f2fd', 'text_color': '#1565c0', 'value_color': '#1976d2'},
'cholesterol': {'icon': 'π§ͺ', 'bg_color': '#fce4ec', 'text_color': '#ad1457', 'value_color': '#c2185b'},
'hemoglobin': {'icon': 'π©Έ', 'bg_color': '#ffebee', 'text_color': '#c62828', 'value_color': '#d32f2f'},
'symptoms': {'icon': 'π€', 'bg_color': '#fff8e1', 'text_color': '#f57f17', 'value_color': '#f9a825'}
}
return color_schemes.get(key, {
'icon': 'π',
'bg_color': '#f5f5f5',
'text_color': '#424242',
'value_color': '#616161'
})
def get_parameter_status(self, key, value):
"""Get status indicator for medical parameter"""
try:
if key in ['systolic_bp', 'diastolic_bp']:
val = int(value)
if key == 'systolic_bp':
if val >= 140:
return {'text': 'β οΈ HIGH', 'color': '#d32f2f'}
elif val < 90:
return {'text': 'β οΈ LOW', 'color': '#1976d2'}
else:
return {'text': 'β
NORMAL', 'color': '#388e3c'}
else: # diastolic_bp
if val >= 90:
return {'text': 'β οΈ HIGH', 'color': '#d32f2f'}
elif val < 60:
return {'text': 'β οΈ LOW', 'color': '#1976d2'}
else:
return {'text': 'β
NORMAL', 'color': '#388e3c'}
elif key == 'heart_rate':
val = int(value)
if val > 100:
return {'text': 'β οΈ HIGH', 'color': '#d32f2f'}
elif val < 60:
return {'text': 'β οΈ LOW', 'color': '#1976d2'}
else:
return {'text': 'β
NORMAL', 'color': '#388e3c'}
elif key == 'glucose':
val = int(value)
if val >= 126:
return {'text': 'β οΈ HIGH', 'color': '#d32f2f'}
elif val < 70:
return {'text': 'β οΈ LOW', 'color': '#1976d2'}