Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
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 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
inputs=None,
|
| 232 |
-
outputs=
|
| 233 |
-
title="CSRC Car Manual RAG System
|
|
|
|
| 234 |
)
|
| 235 |
-
return
|
| 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
|
| 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
|
| 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 |
-
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
import gradio as gr
|
| 266 |
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 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 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 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=
|
| 297 |
inputs=None,
|
| 298 |
-
outputs=
|
| 299 |
-
title="CSRC Car Manual RAG System -
|
|
|
|
| 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 |
+
|