88from server_connector import interact_with_chat
99import subprocess
1010import server_connector
11+ import threading
1112
1213def load_config ():
1314 with open ("config.yaml" , 'r' ) as stream :
@@ -54,10 +55,13 @@ def download_embedding_model(self):
5455
5556 if selected_model :
5657 model_url = f"https://huggingface.co/{ selected_model } "
57-
5858 target_directory = os .path .join ("Embedding_Models" , selected_model .replace ("/" , "--" ))
5959
60- subprocess .run (["git" , "clone" , model_url , target_directory ])
60+ def download_model ():
61+ subprocess .run (["git" , "clone" , model_url , target_directory ])
62+
63+ download_thread = threading .Thread (target = download_model )
64+ download_thread .start ()
6165
6266 def select_embedding_model_directory (self ):
6367 initial_dir = 'Embedding_Models' if os .path .exists ('Embedding_Models' ) else os .path .expanduser ("~" )
@@ -101,7 +105,12 @@ def create_chromadb(self):
101105
102106 if response :
103107 embedding_model_path = getattr (self , "embedding_model_directory" , "" )
104- os .system (f'python ingest_improved.py "{ embedding_model_path } "' )
108+
109+ def run_create_chromadb (embedding_model_path ):
110+ os .system (f'python ingest_improved.py "{ embedding_model_path } "' )
111+
112+ create_chromadb_thread = threading .Thread (target = run_create_chromadb , args = (embedding_model_path ,))
113+ create_chromadb_thread .start ()
105114
106115 def submit_query (self ):
107116 current_dir = os .path .dirname (os .path .realpath (__file__ ))
@@ -120,14 +129,21 @@ def submit_query(self):
120129 return
121130
122131 query = self .gui .text_input .get ("1.0" , tk .END ).strip ()
123- answer = interact_with_chat (query )
124- self .gui .read_only_text .config (state = tk .NORMAL )
125- self .gui .read_only_text .delete ("1.0" , tk .END )
126- self .gui .read_only_text .insert (tk .END , answer )
127- self .gui .read_only_text .config (state = tk .DISABLED )
132+
133+ # Move the chat interaction logic to a separate function
134+ def interact_with_chat_and_update_gui (query ):
135+ answer = interact_with_chat (query )
136+ self .gui .read_only_text .config (state = tk .NORMAL )
137+ self .gui .read_only_text .delete ("1.0" , tk .END )
138+ self .gui .read_only_text .insert (tk .END , answer )
139+ self .gui .read_only_text .config (state = tk .DISABLED )
140+
141+ # Create a thread for chat interaction and GUI update
142+ chat_thread = threading .Thread (target = interact_with_chat_and_update_gui , args = (query ,))
143+ chat_thread .start ()
128144
129145if __name__ == "__main__" :
130146 root = tk .Tk ()
131147 app = DocQA_GUI (root )
132148 logic = DocQA_Logic (app )
133- root .mainloop ()
149+ root .mainloop ()
0 commit comments