4545# Load preset embeddings, vectorstore, and model
4646###
4747
48- embeddings_name = "mixedbread-ai/mxbai-embed-xsmall -v1" #"BAAI/bge-base-en -v1.5"
48+ embeddings_name = "BAAI/bge-base-en -v1.5 " #"mixedbread-ai/mxbai-embed-xsmall -v1"
4949
5050def load_embeddings (embeddings_name = embeddings_name ):
5151
@@ -185,7 +185,7 @@ def docs_to_faiss_save(docs_out:PandasDataFrame, embeddings=embeddings):
185185# RUN UI
186186###
187187
188- app = gr .Blocks (theme = gr .themes .Base ())#css=".gradio-container {background-color: black}")
188+ app = gr .Blocks (theme = gr .themes .Base (), fill_width = True )#css=".gradio-container {background-color: black}")
189189
190190with app :
191191 ingest_text = gr .State ()
@@ -243,9 +243,9 @@ def docs_to_faiss_save(docs_out:PandasDataFrame, embeddings=embeddings):
243243 lines = 1 ,
244244 )
245245 with gr .Row ():
246- submit = gr .Button (value = "Send message" , variant = "secondary " , scale = 1 )
247- clear = gr .Button (value = "Clear chat" , variant = "secondary" , scale = 0 )
248- stop = gr .Button (value = "Stop generating" , variant = "secondary" , scale = 0 )
246+ submit = gr .Button (value = "Send message" , variant = "primary " , scale = 4 )
247+ clear = gr .Button (value = "Clear chat" , variant = "secondary" , scale = 1 )
248+ stop = gr .Button (value = "Stop generating" , variant = "secondary" , scale = 1 )
249249
250250 examples_set = gr .Radio (label = "Examples for the Lambeth Borough Plan" ,
251251 #value = "What were the five pillars of the previous borough plan?",
@@ -296,45 +296,45 @@ def docs_to_faiss_save(docs_out:PandasDataFrame, embeddings=embeddings):
296296 examples_set .change (fn = chatf .update_message , inputs = [examples_set ], outputs = [message ])
297297
298298 change_model_button .click (fn = chatf .turn_off_interactivity , inputs = [message , chatbot ], outputs = [message , chatbot ], queue = False ).\
299- then (fn = load_model , inputs = [model_choice , gpu_layer_choice ], outputs = [model_type_state , load_text , current_model ]).\
300- then (lambda : chatf .restore_interactivity (), None , [message ], queue = False ).\
301- then (chatf .clear_chat , inputs = [chat_history_state , sources , message , current_topic ], outputs = [chat_history_state , sources , message , current_topic ]).\
302- then (lambda : None , None , chatbot , queue = False )
299+ success (fn = load_model , inputs = [model_choice , gpu_layer_choice ], outputs = [model_type_state , load_text , current_model ]).\
300+ success (lambda : chatf .restore_interactivity (), None , [message ], queue = False ).\
301+ success (chatf .clear_chat , inputs = [chat_history_state , sources , message , current_topic ], outputs = [chat_history_state , sources , message , current_topic ]).\
302+ success (lambda : None , None , chatbot , queue = False )
303303
304304 # Load in a pdf
305305 load_pdf_click = load_pdf .click (ing .parse_file , inputs = [in_pdf ], outputs = [ingest_text , current_source ]).\
306- then (ing .text_to_docs , inputs = [ingest_text ], outputs = [ingest_docs ]).\
307- then (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
308- then (chatf .hide_block , outputs = [examples_set ])
306+ success (ing .text_to_docs , inputs = [ingest_text ], outputs = [ingest_docs ]).\
307+ success (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
308+ success (chatf .hide_block , outputs = [examples_set ])
309309
310310 # Load in a webpage
311311 load_web_click = load_web .click (ing .parse_html , inputs = [in_web , in_div ], outputs = [ingest_text , ingest_metadata , current_source ]).\
312- then (ing .html_text_to_docs , inputs = [ingest_text , ingest_metadata ], outputs = [ingest_docs ]).\
313- then (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
314- then (chatf .hide_block , outputs = [examples_set ])
312+ success (ing .html_text_to_docs , inputs = [ingest_text , ingest_metadata ], outputs = [ingest_docs ]).\
313+ success (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
314+ success (chatf .hide_block , outputs = [examples_set ])
315315
316316 # Load in a csv/excel file
317317 load_csv_click = load_csv .click (ing .parse_csv_or_excel , inputs = [in_csv , in_text_column ], outputs = [ingest_text , current_source ]).\
318- then (ing .csv_excel_text_to_docs , inputs = [ingest_text , in_text_column ], outputs = [ingest_docs ]).\
319- then (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
320- then (chatf .hide_block , outputs = [examples_set ])
318+ success (ing .csv_excel_text_to_docs , inputs = [ingest_text , in_text_column ], outputs = [ingest_docs ]).\
319+ success (embed_faiss_save_to_zip , inputs = [ingest_docs ], outputs = [ingest_embed_out , vectorstore_state , file_out_box ]).\
320+ success (chatf .hide_block , outputs = [examples_set ])
321321
322322 # Load in a webpage
323323
324324 # Click/enter to send message action
325325 response_click = submit .click (chatf .create_full_prompt , inputs = [message , chat_history_state , current_topic , vectorstore_state , embeddings_state , model_type_state , out_passages , api_model_choice , in_api_key ], outputs = [chat_history_state , sources , instruction_prompt_out , relevant_query_state ], queue = False , api_name = "retrieval" ).\
326- then (chatf .turn_off_interactivity , inputs = [message , chatbot ], outputs = [message , chatbot ], queue = False ).\
327- then (chatf .produce_streaming_answer_chatbot , inputs = [chatbot , instruction_prompt_out , model_type_state , temp_slide , relevant_query_state ], outputs = chatbot )
328- response_click .then (chatf .highlight_found_text , [chatbot , sources ], [sources ]).\
329- then (chatf .add_inputs_answer_to_history ,[message , chatbot , current_topic ], [chat_history_state , current_topic ]).\
330- then (lambda : chatf .restore_interactivity (), None , [message ], queue = False )
326+ success (chatf .turn_off_interactivity , inputs = [message , chatbot ], outputs = [message , chatbot ], queue = False ).\
327+ success (chatf .produce_streaming_answer_chatbot , inputs = [chatbot , instruction_prompt_out , model_type_state , temp_slide , relevant_query_state ], outputs = chatbot )
328+ response_click .success (chatf .highlight_found_text , [chatbot , sources ], [sources ]).\
329+ success (chatf .add_inputs_answer_to_history ,[message , chatbot , current_topic ], [chat_history_state , current_topic ]).\
330+ success (lambda : chatf .restore_interactivity (), None , [message ], queue = False )
331331
332332 response_enter = message .submit (chatf .create_full_prompt , inputs = [message , chat_history_state , current_topic , vectorstore_state , embeddings_state , model_type_state , out_passages , api_model_choice , in_api_key ], outputs = [chat_history_state , sources , instruction_prompt_out , relevant_query_state ], queue = False ).\
333- then (chatf .turn_off_interactivity , inputs = [message , chatbot ], outputs = [message , chatbot ], queue = False ).\
334- then (chatf .produce_streaming_answer_chatbot , [chatbot , instruction_prompt_out , model_type_state , temp_slide , relevant_query_state ], chatbot )
335- response_enter .then (chatf .highlight_found_text , [chatbot , sources ], [sources ]).\
336- then (chatf .add_inputs_answer_to_history ,[message , chatbot , current_topic ], [chat_history_state , current_topic ]).\
337- then (lambda : chatf .restore_interactivity (), None , [message ], queue = False )
333+ success (chatf .turn_off_interactivity , inputs = [message , chatbot ], outputs = [message , chatbot ], queue = False ).\
334+ success (chatf .produce_streaming_answer_chatbot , [chatbot , instruction_prompt_out , model_type_state , temp_slide , relevant_query_state ], chatbot )
335+ response_enter .success (chatf .highlight_found_text , [chatbot , sources ], [sources ]).\
336+ success (chatf .add_inputs_answer_to_history ,[message , chatbot , current_topic ], [chat_history_state , current_topic ]).\
337+ success (lambda : chatf .restore_interactivity (), None , [message ], queue = False )
338338
339339 # Stop box
340340 stop .click (fn = None , inputs = None , outputs = None , cancels = [response_click , response_enter ])
@@ -356,7 +356,7 @@ def docs_to_faiss_save(docs_out:PandasDataFrame, embeddings=embeddings):
356356 access_callback .setup ([session_hash_textbox ], access_logs_data_folder )
357357
358358 session_hash_textbox .change (lambda * args : access_callback .flag (list (args )), [session_hash_textbox ], None , preprocess = False ).\
359- then (fn = upload_file_to_s3 , inputs = [access_logs_state , access_s3_logs_loc_state ], outputs = [s3_logs_output_textbox ])
359+ success (fn = upload_file_to_s3 , inputs = [access_logs_state , access_s3_logs_loc_state ], outputs = [s3_logs_output_textbox ])
360360
361361# Launch the Gradio app
362362COGNITO_AUTH = get_or_create_env_var ('COGNITO_AUTH' , '0' )
0 commit comments