@@ -169,7 +169,7 @@ def preproc(s):
169
169
170
170
# Using API call to get the tweets of the desired handle
171
171
def getTweets (user ):
172
- csvFile = open ('Resource_Images/user.csv' , 'w' , newline = '' )
172
+ csvFile = open (resource_path ( 'Resource_Images/user.csv' ) , 'w' , newline = '' )
173
173
csvWriter = csv .writer (csvFile )
174
174
try :
175
175
for i in range (0 , 4 ):
@@ -213,21 +213,21 @@ def twits(handle):
213
213
# I/E, S/N, T/Fand P/J is chosen to get the personality. These letters are chosen on the basis of higher frequency.
214
214
def twit (handle ):
215
215
getTweets (handle )
216
- with open ('Resource_Images/user.csv' , 'rt' ) as f :
216
+ with open (resource_path ( 'Resource_Images/user.csv' ) , 'rt' ) as f :
217
217
csvReader = csv .reader (f )
218
218
tweetList = [rows [0 ] for rows in csvReader ]
219
- with open ('Resource_Images/newfrequency300.csv' , 'rt' ) as f :
219
+ with open (resource_path ( 'Resource_Images/newfrequency300.csv' ) , 'rt' ) as f :
220
220
csvReader = csv .reader (f )
221
221
mydict = {rows [1 ]: int (rows [0 ]) for rows in csvReader }
222
222
223
223
vectorizer = TfidfVectorizer (vocabulary = mydict , min_df = 1 )
224
224
x = vectorizer .fit_transform (tweetList ).toarray ()
225
225
df = pd .DataFrame (x )
226
226
227
- model_IE = pickle .load (open ("Resource_Images/BNIEFinal.sav" , 'rb' ))
228
- model_SN = pickle .load (open ("Resource_Images/BNSNFinal.sav" , 'rb' ))
229
- model_TF = pickle .load (open ('Resource_Images/BNTFFinal.sav' , 'rb' ))
230
- model_PJ = pickle .load (open ('Resource_Images/BNPJFinal.sav' , 'rb' ))
227
+ model_IE = pickle .load (open (resource_path ( "Resource_Images/BNIEFinal.sav" ) , 'rb' ))
228
+ model_SN = pickle .load (open (resource_path ( "Resource_Images/BNSNFinal.sav" ) , 'rb' ))
229
+ model_TF = pickle .load (open (resource_path ( 'Resource_Images/BNTFFinal.sav' ) , 'rb' ))
230
+ model_PJ = pickle .load (open (resource_path ( 'Resource_Images/BNPJFinal.sav' ) , 'rb' ))
231
231
232
232
answer = []
233
233
IE = model_IE .predict (df )
@@ -453,6 +453,16 @@ def pp(handle):
453
453
return personality , recomend (personality ), charcter (personality )
454
454
455
455
456
+ def resource_path (relative_path ):
457
+ try :
458
+ # PyInstaller creates a temp folder and stores path in _MEIPASS
459
+ base_path = sys ._MEIPASS
460
+ except Exception :
461
+ base_path = os .path .abspath ("." )
462
+
463
+ return os .path .join (base_path , relative_path )
464
+
465
+
456
466
# Creating the Tkinter frontend for proper interaction
457
467
from tkinter import *
458
468
from PIL import ImageTk
@@ -484,7 +494,7 @@ def mbti(self):
484
494
self .btn1 = ttk .Button (newwin , text = 'EXPLORATORY DATA' , style = 'Accent.TButton' ,
485
495
command = lambda : [self .explore (), newwin .destroy ()])
486
496
self .btn1 .place (x = 710 , y = 120 )
487
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/data_info.png" )
497
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/data_info.png" ) )
488
498
canvas = Canvas (newwin , width = 2500 , height = 2000 )
489
499
canvas .pack (expand = True , fill = BOTH )
490
500
canvas .pack (padx = 0 , pady = 170 )
@@ -496,7 +506,8 @@ def mbti(self):
496
506
def mbt (self ):
497
507
newwin1 = Toplevel (window )
498
508
newwin1 .geometry ("1280x720" )
499
- self .D_lbl0 = ttk .Label (newwin1 , text = 'Personality Based Job Recommender Using Twitter Data' , font = ("Arial" , 15 ))
509
+ self .D_lbl0 = ttk .Label (newwin1 , text = 'Personality Based Job Recommender Using Twitter Data' ,
510
+ font = ("Arial" , 15 ))
500
511
self .D_lbl0 .place (x = 400 , y = 30 )
501
512
self .btn1 = ttk .Button (newwin1 , text = 'MBTI DATA' , style = 'Accent.TButton' ,
502
513
command = lambda : [self .mbti (), newwin1 .destroy ()])
@@ -513,7 +524,7 @@ def mbt(self):
513
524
canvas = Canvas (newwin1 , width = 2500 , height = 2000 )
514
525
canvas .pack (expand = True , fill = BOTH )
515
526
canvas .pack (padx = 0 , pady = 170 )
516
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/TestResults.png" )
527
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/TestResults.png" ) )
517
528
canvas .create_image (1050 , 70 , image = self .bg1 , anchor = "ne" )
518
529
519
530
def explore (self ):
@@ -522,10 +533,11 @@ def explore(self):
522
533
canvas = Canvas (newwin2 , width = 2500 , height = 2000 )
523
534
canvas .pack (expand = True , fill = BOTH )
524
535
canvas .pack (padx = 0 , pady = 100 )
525
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/CountPlot.png" )
536
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/CountPlot.png" ) )
526
537
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
527
538
528
- self .D_lbl0 = ttk .Label (newwin2 , text = 'Personality Based Job Recommender Using Twitter Data' , font = ("Arial" , 15 ))
539
+ self .D_lbl0 = ttk .Label (newwin2 , text = 'Personality Based Job Recommender Using Twitter Data' ,
540
+ font = ("Arial" , 15 ))
529
541
self .D_lbl0 .place (x = 400 , y = 30 )
530
542
self .btn1 = ttk .Button (newwin2 , text = 'MBTI DATA' , style = 'Accent.TButton' ,
531
543
command = lambda : [self .mbti (), newwin2 .destroy ()])
@@ -564,7 +576,7 @@ def explore1(self):
564
576
canvas = Canvas (newwin3 , width = 2500 , height = 2000 )
565
577
canvas .pack (expand = True , fill = BOTH )
566
578
canvas .pack (padx = 0 , pady = 100 )
567
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/PiePlot.png" )
579
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/PiePlot.png" ) )
568
580
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
569
581
570
582
self .D_lbl0 = ttk .Label (newwin3 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -606,7 +618,7 @@ def explore2(self):
606
618
newwin4 .geometry ("1280x720" )
607
619
canvas = Canvas (newwin4 , width = 2500 , height = 2000 )
608
620
canvas .pack (padx = 0 , pady = 100 )
609
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/Displot.png" )
621
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/Displot.png" ) )
610
622
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
611
623
612
624
self .D_lbl0 = ttk .Label (newwin4 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -649,7 +661,7 @@ def explore3(self):
649
661
canvas = Canvas (newwin5 , width = 2500 , height = 2000 )
650
662
canvas .pack (expand = True , fill = BOTH )
651
663
canvas .pack (padx = 0 , pady = 100 )
652
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/I_E.png" )
664
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/I_E.png" ) )
653
665
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
654
666
655
667
self .D_lbl0 = ttk .Label (newwin5 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -692,7 +704,7 @@ def explore4(self):
692
704
canvas = Canvas (newwin6 , width = 2500 , height = 2000 )
693
705
canvas .pack (expand = True , fill = BOTH )
694
706
canvas .pack (padx = 0 , pady = 100 )
695
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/N_S.png" )
707
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/N_S.png" ) )
696
708
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
697
709
698
710
self .D_lbl0 = ttk .Label (newwin6 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -735,7 +747,7 @@ def explore5(self):
735
747
canvas = Canvas (newwin7 , width = 2500 , height = 2000 )
736
748
canvas .pack (expand = True , fill = BOTH )
737
749
canvas .pack (padx = 0 , pady = 100 )
738
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/T_F.png" )
750
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/T_F.png" ) )
739
751
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
740
752
741
753
self .D_lbl0 = ttk .Label (newwin7 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -778,7 +790,7 @@ def explore6(self):
778
790
canvas = Canvas (newwin8 , width = 2500 , height = 2000 )
779
791
canvas .pack (expand = True , fill = BOTH )
780
792
canvas .pack (padx = 0 , pady = 100 )
781
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/J_P.png" )
793
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/J_P.png" ) )
782
794
canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
783
795
784
796
self .D_lbl0 = ttk .Label (newwin8 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -932,8 +944,8 @@ def recomends(self):
932
944
self .s .place (x = 200 , y = 570 )
933
945
self .f = ttk .Label (newwin11 , text = 'F - Feeling' )
934
946
self .f .place (x = 100 , y = 590 )
935
- self .t = ttk .Label (newwin11 , text = 'T - Thinking' )
936
- self .t .place (x = 200 , y = 590 )
947
+ self .tt = ttk .Label (newwin11 , text = 'T - Thinking' )
948
+ self .tt .place (x = 200 , y = 590 )
937
949
self .j = ttk .Label (newwin11 , text = 'J - Judging' )
938
950
self .j .place (x = 100 , y = 610 )
939
951
self .p = ttk .Label (newwin11 , text = 'P - Perceiving' )
@@ -1000,8 +1012,8 @@ def home(self):
1000
1012
self .s .place (x = 200 , y = 570 )
1001
1013
self .f = ttk .Label (newwin12 , text = 'F - Feeling' )
1002
1014
self .f .place (x = 100 , y = 590 )
1003
- self .t = ttk .Label (newwin12 , text = 'T - Thinking' )
1004
- self .t .place (x = 200 , y = 590 )
1015
+ self .tt = ttk .Label (newwin12 , text = 'T - Thinking' )
1016
+ self .tt .place (x = 200 , y = 590 )
1005
1017
self .j = ttk .Label (newwin12 , text = 'J - Judging' )
1006
1018
self .j .place (x = 100 , y = 610 )
1007
1019
self .p = ttk .Label (newwin12 , text = 'P - Perceiving' )
@@ -1028,7 +1040,7 @@ def predict(self):
1028
1040
def home1 (self ):
1029
1041
newwin13 = Toplevel (window )
1030
1042
newwin13 .geometry ("600x600" )
1031
- self .bg1 = ImageTk .PhotoImage (file = "Resource_Images/Home.png" )
1043
+ self .bg1 = ImageTk .PhotoImage (file = resource_path ( "Resource_Images/Home.png" ) )
1032
1044
canvas = Canvas (newwin13 , width = 50 , height = 60 )
1033
1045
canvas .pack (expand = True , fill = BOTH )
1034
1046
canvas .pack (padx = 0 , pady = 170 )
@@ -1047,14 +1059,13 @@ def home1(self):
1047
1059
from tkinter import ttk
1048
1060
1049
1061
window = tk .Tk ()
1050
-
1051
- window .tk .call ('source' , 'Resource_Images/forest-dark.tcl' )
1062
+ window .tk .call ('source' , resource_path (resource_path ('Resource_Images/forest-dark.tcl' )))
1052
1063
1053
1064
# Set the theme with the theme_use method
1054
1065
ttk .Style ().theme_use ('forest-dark' )
1055
1066
1056
1067
window .title ("ENIGMA" )
1057
1068
mywin = MyWindow (window )
1058
1069
window .geometry ("400x300" )
1059
- window .iconphoto (True , tk .PhotoImage (file = 'Resource_Images/icon.png' ))
1070
+ window .iconphoto (True , tk .PhotoImage (file = resource_path ( 'Resource_Images/icon.png' ) ))
1060
1071
window .mainloop ()
0 commit comments