Bryceeee commited on
Commit
3f7a0f7
Β·
verified Β·
1 Parent(s): c4dd944

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -13
app.py CHANGED
@@ -199,21 +199,82 @@ def create_app():
199
 
200
  # Build Gradio interface
201
  print("\n🌐 Building Gradio interface...")
202
- interface_builder = GradioInterfaceBuilder(
203
- rag_engine=components["rag_engine"],
204
- question_generator=components["question_generator"],
205
- knowledge_graph=components["knowledge_graph"],
206
- config=components["config"],
207
- user_profiling=components["user_profiling"],
208
- adaptive_engine=components["adaptive_engine"],
209
- proactive_engine=components["proactive_engine"]
210
- )
211
-
212
- demo = interface_builder.create_interface()
213
- return demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
 
216
  # Create the app for Hugging Face Spaces
217
  # Spaces will automatically detect Gradio and run this
218
- demo = create_app()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
 
199
 
200
  # Build Gradio interface
201
  print("\n🌐 Building Gradio interface...")
202
+ try:
203
+ interface_builder = GradioInterfaceBuilder(
204
+ rag_engine=components["rag_engine"],
205
+ question_generator=components["question_generator"],
206
+ knowledge_graph=components["knowledge_graph"],
207
+ config=components["config"],
208
+ user_profiling=components["user_profiling"],
209
+ adaptive_engine=components["adaptive_engine"],
210
+ proactive_engine=components["proactive_engine"]
211
+ )
212
+
213
+ print("πŸ“¦ Creating interface components...")
214
+ demo = interface_builder.create_interface()
215
+ print("βœ… Gradio interface created successfully!")
216
+ return demo
217
+ except Exception as e:
218
+ print(f"❌ Error building Gradio interface: {e}")
219
+ import traceback
220
+ traceback.print_exc()
221
+
222
+ # Return error interface
223
+ import gradio as gr
224
+ error_msg = f"""
225
+ # ❌ Interface Building Error
226
+
227
+ **Error:** {str(e)}
228
+
229
+ **Possible solutions:**
230
+ 1. Check Gradio version compatibility
231
+ 2. Check the logs for detailed error information
232
+ 3. Verify all dependencies are installed correctly
233
+
234
+ **Traceback:**
235
+ ```
236
+ {traceback.format_exc()}
237
+ ```
238
+ """
239
+
240
+ def error_display():
241
+ return error_msg
242
+
243
+ error_interface = gr.Interface(
244
+ fn=error_display,
245
+ inputs=None,
246
+ outputs=gr.Markdown(),
247
+ title="CSRC Car Manual RAG System",
248
+ description="An error occurred while building the interface. Please check the logs."
249
+ )
250
+ return error_interface
251
 
252
 
253
  # Create the app for Hugging Face Spaces
254
  # Spaces will automatically detect Gradio and run this
255
+ # Use a guard to prevent multiple initializations (Spaces may import the module multiple times)
256
+ _demo_initialized = False
257
+
258
+ if not _demo_initialized:
259
+ try:
260
+ print("πŸ”„ Initializing app...")
261
+ demo = create_app()
262
+ _demo_initialized = True
263
+ print("βœ… App initialized successfully!")
264
+ except Exception as e:
265
+ print(f"❌ Error creating app: {e}")
266
+ import traceback
267
+ traceback.print_exc()
268
+ # Create a minimal error interface
269
+ import gradio as gr
270
+ demo = gr.Interface(
271
+ fn=lambda: f"Error: {str(e)}\n\nPlease check the logs for details.",
272
+ inputs=None,
273
+ outputs=gr.Textbox(),
274
+ title="CSRC Car Manual RAG System - Error",
275
+ description="An error occurred during initialization. Please check the logs."
276
+ )
277
+ _demo_initialized = True
278
+ else:
279
+ print("ℹ️ App already initialized, reusing existing instance")
280