Spaces:
Runtime error
Runtime error
Initialize demo variable first, then create - ensure it's always set
Browse files
app.py
CHANGED
|
@@ -843,9 +843,11 @@ IS_SPACES = (
|
|
| 843 |
os.getenv("HF_SPACE_ID") is not None
|
| 844 |
)
|
| 845 |
|
| 846 |
-
#
|
|
|
|
|
|
|
|
|
|
| 847 |
# This ensures Spaces can always find it when importing the module
|
| 848 |
-
# For local execution, we'll still create it here but main() will also create its own
|
| 849 |
try:
|
| 850 |
if IS_SPACES:
|
| 851 |
logger.info("Initializing for Hugging Face Spaces...")
|
|
@@ -895,8 +897,8 @@ except Exception as e:
|
|
| 895 |
logger.info(f"Error demo created: {type(demo)}")
|
| 896 |
|
| 897 |
# Final verification - ensure demo exists and is valid
|
| 898 |
-
if
|
| 899 |
-
logger.error("CRITICAL: Demo variable is
|
| 900 |
with gr.Blocks() as demo:
|
| 901 |
gr.Markdown("# Error: Demo was not created properly\n\nPlease check the logs for details.")
|
| 902 |
elif not isinstance(demo, (gr.Blocks, gr.Interface)):
|
|
@@ -904,7 +906,7 @@ elif not isinstance(demo, (gr.Blocks, gr.Interface)):
|
|
| 904 |
with gr.Blocks() as demo:
|
| 905 |
gr.Markdown(f"# Error: Invalid demo type\n\nDemo type: {type(demo)}\n\nPlease check the logs for details.")
|
| 906 |
else:
|
| 907 |
-
logger.info(f"✅ Final demo check passed: demo
|
| 908 |
|
| 909 |
# For local execution only (not on Spaces)
|
| 910 |
if __name__ == "__main__":
|
|
|
|
| 843 |
os.getenv("HF_SPACE_ID") is not None
|
| 844 |
)
|
| 845 |
|
| 846 |
+
# Initialize demo variable to None first (safety measure)
|
| 847 |
+
demo = None
|
| 848 |
+
|
| 849 |
+
# Create demo at module level (like HF docs example)
|
| 850 |
# This ensures Spaces can always find it when importing the module
|
|
|
|
| 851 |
try:
|
| 852 |
if IS_SPACES:
|
| 853 |
logger.info("Initializing for Hugging Face Spaces...")
|
|
|
|
| 897 |
logger.info(f"Error demo created: {type(demo)}")
|
| 898 |
|
| 899 |
# Final verification - ensure demo exists and is valid
|
| 900 |
+
if demo is None:
|
| 901 |
+
logger.error("CRITICAL: Demo variable is None!")
|
| 902 |
with gr.Blocks() as demo:
|
| 903 |
gr.Markdown("# Error: Demo was not created properly\n\nPlease check the logs for details.")
|
| 904 |
elif not isinstance(demo, (gr.Blocks, gr.Interface)):
|
|
|
|
| 906 |
with gr.Blocks() as demo:
|
| 907 |
gr.Markdown(f"# Error: Invalid demo type\n\nDemo type: {type(demo)}\n\nPlease check the logs for details.")
|
| 908 |
else:
|
| 909 |
+
logger.info(f"✅ Final demo check passed: demo type={type(demo)}")
|
| 910 |
|
| 911 |
# For local execution only (not on Spaces)
|
| 912 |
if __name__ == "__main__":
|