@@ -169,7 +169,7 @@ def preproc(s):
169169
170170# Using API call to get the tweets of the desired handle
171171def getTweets (user ):
172- csvFile = open ('Resource_Images/user.csv' , 'w' , newline = '' )
172+ csvFile = open (resource_path ( 'Resource_Images/user.csv' ) , 'w' , newline = '' )
173173 csvWriter = csv .writer (csvFile )
174174 try :
175175 for i in range (0 , 4 ):
@@ -213,21 +213,21 @@ def twits(handle):
213213# I/E, S/N, T/Fand P/J is chosen to get the personality. These letters are chosen on the basis of higher frequency.
214214def twit (handle ):
215215 getTweets (handle )
216- with open ('Resource_Images/user.csv' , 'rt' ) as f :
216+ with open (resource_path ( 'Resource_Images/user.csv' ) , 'rt' ) as f :
217217 csvReader = csv .reader (f )
218218 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 :
220220 csvReader = csv .reader (f )
221221 mydict = {rows [1 ]: int (rows [0 ]) for rows in csvReader }
222222
223223 vectorizer = TfidfVectorizer (vocabulary = mydict , min_df = 1 )
224224 x = vectorizer .fit_transform (tweetList ).toarray ()
225225 df = pd .DataFrame (x )
226226
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' ))
231231
232232 answer = []
233233 IE = model_IE .predict (df )
@@ -453,6 +453,16 @@ def pp(handle):
453453 return personality , recomend (personality ), charcter (personality )
454454
455455
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+
456466# Creating the Tkinter frontend for proper interaction
457467from tkinter import *
458468from PIL import ImageTk
@@ -484,7 +494,7 @@ def mbti(self):
484494 self .btn1 = ttk .Button (newwin , text = 'EXPLORATORY DATA' , style = 'Accent.TButton' ,
485495 command = lambda : [self .explore (), newwin .destroy ()])
486496 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" ) )
488498 canvas = Canvas (newwin , width = 2500 , height = 2000 )
489499 canvas .pack (expand = True , fill = BOTH )
490500 canvas .pack (padx = 0 , pady = 170 )
@@ -496,7 +506,8 @@ def mbti(self):
496506 def mbt (self ):
497507 newwin1 = Toplevel (window )
498508 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 ))
500511 self .D_lbl0 .place (x = 400 , y = 30 )
501512 self .btn1 = ttk .Button (newwin1 , text = 'MBTI DATA' , style = 'Accent.TButton' ,
502513 command = lambda : [self .mbti (), newwin1 .destroy ()])
@@ -513,7 +524,7 @@ def mbt(self):
513524 canvas = Canvas (newwin1 , width = 2500 , height = 2000 )
514525 canvas .pack (expand = True , fill = BOTH )
515526 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" ) )
517528 canvas .create_image (1050 , 70 , image = self .bg1 , anchor = "ne" )
518529
519530 def explore (self ):
@@ -522,10 +533,11 @@ def explore(self):
522533 canvas = Canvas (newwin2 , width = 2500 , height = 2000 )
523534 canvas .pack (expand = True , fill = BOTH )
524535 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" ) )
526537 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
527538
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 ))
529541 self .D_lbl0 .place (x = 400 , y = 30 )
530542 self .btn1 = ttk .Button (newwin2 , text = 'MBTI DATA' , style = 'Accent.TButton' ,
531543 command = lambda : [self .mbti (), newwin2 .destroy ()])
@@ -564,7 +576,7 @@ def explore1(self):
564576 canvas = Canvas (newwin3 , width = 2500 , height = 2000 )
565577 canvas .pack (expand = True , fill = BOTH )
566578 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" ) )
568580 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
569581
570582 self .D_lbl0 = ttk .Label (newwin3 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -606,7 +618,7 @@ def explore2(self):
606618 newwin4 .geometry ("1280x720" )
607619 canvas = Canvas (newwin4 , width = 2500 , height = 2000 )
608620 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" ) )
610622 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
611623
612624 self .D_lbl0 = ttk .Label (newwin4 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -649,7 +661,7 @@ def explore3(self):
649661 canvas = Canvas (newwin5 , width = 2500 , height = 2000 )
650662 canvas .pack (expand = True , fill = BOTH )
651663 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" ) )
653665 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
654666
655667 self .D_lbl0 = ttk .Label (newwin5 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -692,7 +704,7 @@ def explore4(self):
692704 canvas = Canvas (newwin6 , width = 2500 , height = 2000 )
693705 canvas .pack (expand = True , fill = BOTH )
694706 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" ) )
696708 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
697709
698710 self .D_lbl0 = ttk .Label (newwin6 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -735,7 +747,7 @@ def explore5(self):
735747 canvas = Canvas (newwin7 , width = 2500 , height = 2000 )
736748 canvas .pack (expand = True , fill = BOTH )
737749 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" ) )
739751 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
740752
741753 self .D_lbl0 = ttk .Label (newwin7 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -778,7 +790,7 @@ def explore6(self):
778790 canvas = Canvas (newwin8 , width = 2500 , height = 2000 )
779791 canvas .pack (expand = True , fill = BOTH )
780792 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" ) )
782794 canvas .create_image (50 , 70 , image = self .bg1 , anchor = "nw" )
783795
784796 self .D_lbl0 = ttk .Label (newwin8 , text = 'Personality Based Job Recommender Using Twitter Data' ,
@@ -932,8 +944,8 @@ def recomends(self):
932944 self .s .place (x = 200 , y = 570 )
933945 self .f = ttk .Label (newwin11 , text = 'F - Feeling' )
934946 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 )
937949 self .j = ttk .Label (newwin11 , text = 'J - Judging' )
938950 self .j .place (x = 100 , y = 610 )
939951 self .p = ttk .Label (newwin11 , text = 'P - Perceiving' )
@@ -1000,8 +1012,8 @@ def home(self):
10001012 self .s .place (x = 200 , y = 570 )
10011013 self .f = ttk .Label (newwin12 , text = 'F - Feeling' )
10021014 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 )
10051017 self .j = ttk .Label (newwin12 , text = 'J - Judging' )
10061018 self .j .place (x = 100 , y = 610 )
10071019 self .p = ttk .Label (newwin12 , text = 'P - Perceiving' )
@@ -1028,7 +1040,7 @@ def predict(self):
10281040 def home1 (self ):
10291041 newwin13 = Toplevel (window )
10301042 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" ) )
10321044 canvas = Canvas (newwin13 , width = 50 , height = 60 )
10331045 canvas .pack (expand = True , fill = BOTH )
10341046 canvas .pack (padx = 0 , pady = 170 )
@@ -1047,14 +1059,13 @@ def home1(self):
10471059from tkinter import ttk
10481060
10491061window = 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' )))
10521063
10531064# Set the theme with the theme_use method
10541065ttk .Style ().theme_use ('forest-dark' )
10551066
10561067window .title ("ENIGMA" )
10571068mywin = MyWindow (window )
10581069window .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' ) ))
10601071window .mainloop ()
0 commit comments