Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -239,43 +239,65 @@ def create_app():
|
|
| 239 |
# Spaces will automatically detect Gradio and run this
|
| 240 |
# The demo variable must be exposed at module level for Spaces to detect it
|
| 241 |
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
-
|
|
|
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
demo = gr.Interface(
|
| 274 |
-
fn=
|
| 275 |
inputs=None,
|
| 276 |
-
outputs=
|
| 277 |
-
title="CSRC Car Manual RAG System -
|
| 278 |
-
description="An error occurred. Please check the logs."
|
| 279 |
)
|
| 280 |
|
| 281 |
# Note: Do NOT call demo.launch() here
|
|
|
|
| 239 |
# Spaces will automatically detect Gradio and run this
|
| 240 |
# The demo variable must be exposed at module level for Spaces to detect it
|
| 241 |
|
| 242 |
+
# Initialize demo to None first
|
| 243 |
+
demo = None
|
| 244 |
+
|
| 245 |
+
# Only initialize once (prevent duplicate initialization)
|
| 246 |
+
if demo is None:
|
| 247 |
+
try:
|
| 248 |
+
print("π Starting app initialization...")
|
| 249 |
+
demo = create_app()
|
| 250 |
+
print("β
App created successfully!")
|
| 251 |
+
print(f"β
Demo type: {type(demo)}")
|
| 252 |
+
print(f"β
Demo object: {demo}")
|
| 253 |
+
|
| 254 |
+
# Verify demo is a valid Gradio Blocks object
|
| 255 |
+
if demo is None:
|
| 256 |
+
raise ValueError("Demo object is None after creation")
|
| 257 |
+
if not hasattr(demo, 'launch'):
|
| 258 |
+
raise ValueError("Demo object does not have launch method")
|
| 259 |
+
|
| 260 |
+
except Exception as e:
|
| 261 |
+
print(f"β Fatal error creating app: {e}")
|
| 262 |
+
import traceback
|
| 263 |
+
traceback.print_exc()
|
| 264 |
|
| 265 |
+
# Create a minimal error interface
|
| 266 |
+
import gradio as gr
|
| 267 |
|
| 268 |
+
def show_error():
|
| 269 |
+
return f"""
|
| 270 |
+
# β Application Error
|
| 271 |
+
|
| 272 |
+
**Fatal Error:** {str(e)}
|
| 273 |
+
|
| 274 |
+
Please check:
|
| 275 |
+
1. OPENAI_API_KEY is set in Spaces Secrets
|
| 276 |
+
2. All required files are uploaded
|
| 277 |
+
3. Check the logs for detailed error information
|
| 278 |
+
|
| 279 |
+
**Traceback:**
|
| 280 |
+
```
|
| 281 |
+
{traceback.format_exc()}
|
| 282 |
+
```
|
| 283 |
+
"""
|
| 284 |
|
| 285 |
+
demo = gr.Interface(
|
| 286 |
+
fn=show_error,
|
| 287 |
+
inputs=None,
|
| 288 |
+
outputs=gr.Markdown(),
|
| 289 |
+
title="CSRC Car Manual RAG System - Error",
|
| 290 |
+
description="An error occurred. Please check the logs."
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
# Final verification
|
| 294 |
+
if demo is None:
|
| 295 |
+
import gradio as gr
|
| 296 |
demo = gr.Interface(
|
| 297 |
+
fn=lambda: "Application failed to initialize. Please check the logs.",
|
| 298 |
inputs=None,
|
| 299 |
+
outputs="text",
|
| 300 |
+
title="CSRC Car Manual RAG System - Initialization Failed"
|
|
|
|
| 301 |
)
|
| 302 |
|
| 303 |
# Note: Do NOT call demo.launch() here
|