arahrooh commited on
Commit
bdad35b
·
1 Parent(s): 6edb5d8

Fix: Better error handling in module initialization

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -961,6 +961,10 @@ try:
961
  demo = create_interface(bot, use_inference_api=IS_SPACES)
962
  except Exception as bot_error:
963
  logger.error(f"Error initializing RAGBot: {bot_error}", exc_info=True)
 
 
 
 
964
  # Create a demo that shows the error but still allows the interface to load
965
  with gr.Blocks() as demo:
966
  gr.Markdown(f"""
@@ -970,14 +974,19 @@ try:
970
 
971
  **Error:** {str(bot_error)}
972
 
973
- This might be due to:
974
  - Missing vector database (chroma_db directory)
975
  - Missing dependencies
976
  - Configuration issues
 
 
 
 
 
977
 
978
  Please check the logs for more details.
979
  """)
980
- raise # Re-raise to be caught by outer try/except
981
  logger.info(f"Demo created successfully: {type(demo)}")
982
  # Explicitly verify it's a valid Gradio object
983
  if not isinstance(demo, (gr.Blocks, gr.Interface)):
 
961
  demo = create_interface(bot, use_inference_api=IS_SPACES)
962
  except Exception as bot_error:
963
  logger.error(f"Error initializing RAGBot: {bot_error}", exc_info=True)
964
+ import traceback
965
+ error_trace = traceback.format_exc()
966
+ logger.error(f"Full traceback: {error_trace}")
967
+
968
  # Create a demo that shows the error but still allows the interface to load
969
  with gr.Blocks() as demo:
970
  gr.Markdown(f"""
 
974
 
975
  **Error:** {str(bot_error)}
976
 
977
+ **Possible causes:**
978
  - Missing vector database (chroma_db directory)
979
  - Missing dependencies
980
  - Configuration issues
981
+ - Inference API initialization failed
982
+
983
+ **For Spaces:**
984
+ - Make sure HF_TOKEN is set as a secret
985
+ - Check the logs tab for detailed error messages
986
 
987
  Please check the logs for more details.
988
  """)
989
+ # Don't re-raise - let the demo be created so users can see the error
990
  logger.info(f"Demo created successfully: {type(demo)}")
991
  # Explicitly verify it's a valid Gradio object
992
  if not isinstance(demo, (gr.Blocks, gr.Interface)):