zwq2018 commited on
Commit
d849b80
·
1 Parent(s): 9e66ab7

modified: main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -17
main.py CHANGED
@@ -345,24 +345,30 @@ def run(instruction, add_to_queue=None, send_chat_request_Azure = send_official_
345
 
346
  def gradio_interface(query, openai_key, openai_key_azure, api_base,engine):
347
  # Create a new thread to run the function.
348
- if openai_key.startswith('sk') and openai_key_azure == '':
349
- print('send_official_call')
350
- thread = MyThread(target=run, args=(query, add_to_queue, send_official_call, openai_key))
351
- elif openai_key =='' and len(openai_key_azure)>0:
352
- print('send_chat_request_Azure')
353
- thread = MyThread(target=run, args=(query, add_to_queue, send_chat_request_Azure, openai_key_azure, api_base, engine))
354
- thread.start()
355
  placeholder_image = np.zeros((100, 100, 3), dtype=np.uint8) # Create a placeholder image.
356
- placeholder_dataframe = pd.DataFrame() #
357
-
358
- # Wait for the result of the calculate function and display the intermediate results simultaneously.
359
- while thread.is_alive():
360
- while not intermediate_results.empty():
361
- yield intermediate_results.get(), placeholder_image, 'Running' , placeholder_dataframe # Use the yield keyword to return intermediate results in real-time
362
- time.sleep(0.1) # Avoid excessive resource consumption.
363
-
364
- finally_text, img, output, df = thread.get_result()
365
- yield finally_text, img, output, df
 
 
 
 
 
 
 
 
 
 
 
 
366
  # Return the final result.
367
 
368
 
 
345
 
346
  def gradio_interface(query, openai_key, openai_key_azure, api_base,engine):
347
  # Create a new thread to run the function.
348
+ placeholder_dataframe = pd.DataFrame()
 
 
 
 
 
 
349
  placeholder_image = np.zeros((100, 100, 3), dtype=np.uint8) # Create a placeholder image.
350
+ try:
351
+ if openai_key.startswith('sk') and openai_key_azure == '':
352
+ print('send_official_call')
353
+ thread = MyThread(target=run, args=(query, add_to_queue, send_official_call, openai_key))
354
+ elif openai_key =='' and len(openai_key_azure)>0:
355
+ print('send_chat_request_Azure')
356
+ thread = MyThread(target=run, args=(query, add_to_queue, send_chat_request_Azure, openai_key_azure, api_base, engine))
357
+ thread.start()
358
+
359
+ #
360
+
361
+ # Wait for the result of the calculate function and display the intermediate results simultaneously.
362
+ while thread.is_alive():
363
+ while not intermediate_results.empty():
364
+ yield intermediate_results.get(), placeholder_image, 'Running' , placeholder_dataframe # Use the yield keyword to return intermediate results in real-time
365
+ time.sleep(0.1) # Avoid excessive resource consumption.
366
+
367
+ finally_text, img, output, df = thread.get_result()
368
+ yield finally_text, img, output, df
369
+
370
+ except Exception as e:
371
+ yield str(e), placeholder_image, str(e), placeholder_dataframe
372
  # Return the final result.
373
 
374