Spaces:
Runtime error
Runtime error
Simplify demo creation - remove try/except wrapper that might interfere with Spaces detection
Browse files
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 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 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__":
|