Spaces:
Runtime error
Runtime error
Fix: Remove assertions, ensure demo always exists with proper fallbacks
Browse files
app.py
CHANGED
|
@@ -999,11 +999,19 @@ try:
|
|
| 999 |
""")
|
| 1000 |
logger.info(f"Error demo created: {type(demo)}")
|
| 1001 |
# Don't re-raise - let the demo be created so users can see the error
|
| 1002 |
-
|
| 1003 |
-
#
|
| 1004 |
-
if
|
| 1005 |
-
|
| 1006 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
except Exception as e:
|
| 1008 |
logger.error(f"Error creating demo: {e}", exc_info=True)
|
| 1009 |
import traceback
|
|
@@ -1030,8 +1038,16 @@ else:
|
|
| 1030 |
|
| 1031 |
# CRITICAL: Ensure demo is always set for Spaces
|
| 1032 |
# Spaces will look for a variable named 'demo' at module level
|
| 1033 |
-
|
| 1034 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1035 |
|
| 1036 |
# For local execution only (not on Spaces)
|
| 1037 |
if __name__ == "__main__":
|
|
|
|
| 999 |
""")
|
| 1000 |
logger.info(f"Error demo created: {type(demo)}")
|
| 1001 |
# Don't re-raise - let the demo be created so users can see the error
|
| 1002 |
+
|
| 1003 |
+
# Verify demo was created
|
| 1004 |
+
if demo is None:
|
| 1005 |
+
logger.error("Demo is None after creation attempt!")
|
| 1006 |
+
with gr.Blocks(title="CGT-LLM-Beta RAG Chatbot") as demo:
|
| 1007 |
+
gr.Markdown("# Error: Demo was not created\n\nPlease check the logs.")
|
| 1008 |
+
elif not isinstance(demo, (gr.Blocks, gr.Interface)):
|
| 1009 |
+
logger.error(f"Demo is not a valid Gradio object: {type(demo)}")
|
| 1010 |
+
with gr.Blocks(title="CGT-LLM-Beta RAG Chatbot") as demo:
|
| 1011 |
+
gr.Markdown(f"# Error: Invalid demo type\n\nType: {type(demo)}\n\nPlease check the logs.")
|
| 1012 |
+
else:
|
| 1013 |
+
logger.info(f"Demo created successfully: {type(demo)}")
|
| 1014 |
+
logger.info("Demo validation passed - ready for Spaces")
|
| 1015 |
except Exception as e:
|
| 1016 |
logger.error(f"Error creating demo: {e}", exc_info=True)
|
| 1017 |
import traceback
|
|
|
|
| 1038 |
|
| 1039 |
# CRITICAL: Ensure demo is always set for Spaces
|
| 1040 |
# Spaces will look for a variable named 'demo' at module level
|
| 1041 |
+
# Final safety check - if demo is still None or invalid, create a minimal one
|
| 1042 |
+
if demo is None or not isinstance(demo, (gr.Blocks, gr.Interface)):
|
| 1043 |
+
logger.error("CRITICAL: Demo is invalid, creating emergency fallback")
|
| 1044 |
+
with gr.Blocks(title="CGT-LLM-Beta RAG Chatbot") as demo:
|
| 1045 |
+
gr.Markdown("""
|
| 1046 |
+
# CGT-LLM-Beta RAG Chatbot
|
| 1047 |
+
|
| 1048 |
+
The application encountered an error during initialization.
|
| 1049 |
+
Please check the logs for details.
|
| 1050 |
+
""")
|
| 1051 |
|
| 1052 |
# For local execution only (not on Spaces)
|
| 1053 |
if __name__ == "__main__":
|