arahrooh commited on
Commit
c98a991
·
1 Parent(s): 63dafc0

Simplify demo creation - remove try/except wrapper that might interfere with Spaces detection

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -882,22 +882,17 @@ IS_SPACES = os.getenv("SPACE_ID") is not None or os.getenv("SYSTEM") == "spaces"
882
 
883
  # Create demo unconditionally at module level - Spaces needs this
884
  # For local execution, main() will create its own demo
885
- try:
886
- if IS_SPACES:
887
- logger.info("Initializing for Hugging Face Spaces...")
888
- demo = create_demo_for_spaces() if IS_SPACES else None
889
- if IS_SPACES and demo is not None:
890
- logger.info(f"Demo created successfully: {type(demo)}")
891
- # Verify demo is a valid Gradio object
892
- if not isinstance(demo, (gr.Blocks, gr.Interface)):
893
- logger.error(f"Demo is not a valid Gradio object: {type(demo)}")
894
- raise TypeError(f"Expected gr.Blocks or gr.Interface, got {type(demo)}")
895
- except Exception as e:
896
- logger.error(f"Failed to create demo for Spaces: {e}", exc_info=True)
897
- # Create a fallback error demo so Spaces doesn't show blank
898
- with gr.Blocks() as error_demo:
899
- gr.Markdown(f"# Error Initializing Chatbot\n\nAn error occurred while initializing the chatbot.\n\nError: {str(e)}\n\nPlease check the logs for details.")
900
- demo = error_demo
901
 
902
  # For local execution only (not on Spaces)
903
  if __name__ == "__main__":
 
882
 
883
  # Create demo unconditionally at module level - Spaces needs this
884
  # For local execution, main() will create its own demo
885
+ if IS_SPACES:
886
+ logger.info("Initializing for Hugging Face Spaces...")
887
+ demo = create_demo_for_spaces()
888
+ logger.info(f"Demo created successfully: {type(demo)}")
889
+ # Verify demo is a valid Gradio object
890
+ if not isinstance(demo, (gr.Blocks, gr.Interface)):
891
+ logger.error(f"Demo is not a valid Gradio object: {type(demo)}")
892
+ raise TypeError(f"Expected gr.Blocks or gr.Interface, got {type(demo)}")
893
+ else:
894
+ # Local execution: demo will be created in main()
895
+ demo = None
 
 
 
 
 
896
 
897
  # For local execution only (not on Spaces)
898
  if __name__ == "__main__":