Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -199,21 +199,82 @@ def create_app():
|
|
| 199 |
|
| 200 |
# Build Gradio interface
|
| 201 |
print("\nπ Building Gradio interface...")
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
# Create the app for Hugging Face Spaces
|
| 217 |
# Spaces will automatically detect Gradio and run this
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|