Bryceeee commited on
Commit
7964505
Β·
verified Β·
1 Parent(s): f54ef0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -32
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
- try:
243
- print("πŸ”„ Starting app initialization...")
244
- demo = create_app()
245
- print("βœ… App created successfully!")
246
- print(f"βœ… Demo type: {type(demo)}")
247
- print(f"βœ… Demo object: {demo}")
248
- except Exception as e:
249
- print(f"❌ Fatal error creating app: {e}")
250
- import traceback
251
- traceback.print_exc()
252
-
253
- # Create a minimal error interface
254
- import gradio as gr
255
-
256
- def show_error():
257
- return f"""
258
- # ❌ Application Error
 
 
 
 
 
259
 
260
- **Fatal Error:** {str(e)}
 
261
 
262
- Please check:
263
- 1. OPENAI_API_KEY is set in Spaces Secrets
264
- 2. All required files are uploaded
265
- 3. Check the logs for detailed error information
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
- **Traceback:**
268
- ```
269
- {traceback.format_exc()}
270
- ```
271
- """
272
-
 
 
 
 
 
273
  demo = gr.Interface(
274
- fn=show_error,
275
  inputs=None,
276
- outputs=gr.Markdown(),
277
- title="CSRC Car Manual RAG System - Error",
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