Bryceeee commited on
Commit
cdf3c8a
Β·
verified Β·
1 Parent(s): d080b90

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -52
app.py CHANGED
@@ -1,6 +1,7 @@
1
  """
2
  Hugging Face Spaces Entry Point for CSRC Car Manual RAG System
3
  This is the entry point for Hugging Face Spaces deployment
 
4
  Note: For local development, use main.py instead.
5
  """
6
  import os
@@ -214,91 +215,94 @@ def create_app():
214
  proactive_engine=components["proactive_engine"]
215
  )
216
 
217
- # Create interface
218
- print("Creating Gradio Blocks...")
219
  demo = interface_builder.create_interface()
220
  print("βœ… Gradio interface created successfully!")
221
-
222
  return demo
223
  except Exception as e:
224
  print(f"❌ Error building Gradio interface: {e}")
225
  import traceback
226
  traceback.print_exc()
 
227
  # Return a simple error interface
228
  import gradio as gr
229
- error_demo = gr.Interface(
230
- fn=lambda: f"Error building interface: {str(e)}",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  inputs=None,
232
- outputs="text",
233
- title="CSRC Car Manual RAG System - Interface Error"
 
234
  )
235
- return error_demo
236
 
237
 
238
  # Create the app for Hugging Face Spaces
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
- # Create demo object for Hugging Face Spaces
243
- # Spaces will automatically detect and launch the demo object
244
- # We use a simple approach: create demo directly at module level
245
-
246
  try:
247
  print("πŸ”„ Starting app initialization...")
248
  demo = create_app()
249
  print("βœ… App created successfully!")
250
  print(f"βœ… Demo type: {type(demo)}")
251
- print(f"βœ… Demo object: {demo}")
252
 
253
- # Verify demo is a valid Gradio Blocks object
254
  if demo is None:
255
  raise ValueError("Demo object is None after creation")
256
  if not hasattr(demo, 'launch'):
257
  raise ValueError("Demo object does not have launch method")
258
 
259
  except Exception as e:
260
- print(f"❌ Fatal error creating app: {e}")
261
- import traceback
262
- traceback.print_exc()
 
 
 
 
 
 
 
263
 
264
- # Create a minimal error interface
265
- import gradio as gr
266
 
267
- def show_error():
268
- return f"""
269
- # ❌ Application Error
270
-
271
- **Fatal Error:** {str(e)}
272
-
273
- Please check:
274
- 1. OPENAI_API_KEY is set in Spaces Secrets
275
- 2. All required files are uploaded
276
- 3. Check the logs for detailed error information
277
-
278
- **Traceback:**
279
- ```
280
- {traceback.format_exc()}
281
- ```
282
- """
283
 
284
- demo = gr.Interface(
285
- fn=show_error,
286
- inputs=None,
287
- outputs=gr.Markdown(),
288
- title="CSRC Car Manual RAG System - Error",
289
- description="An error occurred. Please check the logs."
290
- )
291
-
292
- # Ensure demo is always defined (fallback if all else fails)
293
- if 'demo' not in globals() or demo is None:
294
- import gradio as gr
295
  demo = gr.Interface(
296
- fn=lambda: "Application failed to initialize. Please check the logs.",
297
  inputs=None,
298
- outputs="text",
299
- title="CSRC Car Manual RAG System - Initialization Failed"
 
300
  )
301
 
302
  # Note: Do NOT call demo.launch() here
303
  # Hugging Face Spaces will automatically detect and launch the demo
304
- # The demo variable is exposed at module level, which is what Spaces expects
 
 
1
  """
2
  Hugging Face Spaces Entry Point for CSRC Car Manual RAG System
3
  This is the entry point for Hugging Face Spaces deployment
4
+
5
  Note: For local development, use main.py instead.
6
  """
7
  import os
 
215
  proactive_engine=components["proactive_engine"]
216
  )
217
 
 
 
218
  demo = interface_builder.create_interface()
219
  print("βœ… Gradio interface created successfully!")
 
220
  return demo
221
  except Exception as e:
222
  print(f"❌ Error building Gradio interface: {e}")
223
  import traceback
224
  traceback.print_exc()
225
+
226
  # Return a simple error interface
227
  import gradio as gr
228
+ error_msg = f"""
229
+ # ❌ Interface Building Error
230
+
231
+ **Error:** {str(e)}
232
+
233
+ **Possible solutions:**
234
+ 1. Check Gradio version compatibility
235
+ 2. Check the logs for detailed error information
236
+ 3. Verify all dependencies are installed correctly
237
+
238
+ **Traceback:**
239
+ ```
240
+ {traceback.format_exc()}
241
+ ```
242
+ """
243
+
244
+ def error_display():
245
+ return error_msg
246
+
247
+ error_interface = gr.Interface(
248
+ fn=error_display,
249
  inputs=None,
250
+ outputs=gr.Markdown(),
251
+ title="CSRC Car Manual RAG System",
252
+ description="An error occurred while building the interface. Please check the logs."
253
  )
254
+ return error_interface
255
 
256
 
257
  # Create the app for Hugging Face Spaces
258
  # Spaces will automatically detect Gradio and run this
259
+ # The demo variable must be at module level for Spaces to detect it
 
 
 
 
 
260
  try:
261
  print("πŸ”„ Starting app initialization...")
262
  demo = create_app()
263
  print("βœ… App created successfully!")
264
  print(f"βœ… Demo type: {type(demo)}")
 
265
 
266
+ # Verify demo is a valid Gradio object
267
  if demo is None:
268
  raise ValueError("Demo object is None after creation")
269
  if not hasattr(demo, 'launch'):
270
  raise ValueError("Demo object does not have launch method")
271
 
272
  except Exception as e:
273
+ print(f"❌ Fatal error creating app: {e}")
274
+ import traceback
275
+ traceback.print_exc()
276
+
277
+ # Create a minimal error interface as fallback
278
+ import gradio as gr
279
+
280
+ def show_error():
281
+ return f"""
282
+ # ❌ Application Error
283
 
284
+ **Fatal Error:** {str(e)}
 
285
 
286
+ Please check:
287
+ 1. OPENAI_API_KEY is set in Spaces Secrets
288
+ 2. All required files are uploaded
289
+ 3. Check the logs for detailed error information
 
 
 
 
 
 
 
 
 
 
 
 
290
 
291
+ **Traceback:**
292
+ ```
293
+ {traceback.format_exc()}
294
+ ```
295
+ """
296
+
 
 
 
 
 
297
  demo = gr.Interface(
298
+ fn=show_error,
299
  inputs=None,
300
+ outputs=gr.Markdown(),
301
+ title="CSRC Car Manual RAG System - Error",
302
+ description="An error occurred. Please check the logs."
303
  )
304
 
305
  # Note: Do NOT call demo.launch() here
306
  # Hugging Face Spaces will automatically detect and launch the demo
307
+ # The demo variable is exposed at module level, which is what Spaces expects
308
+