Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,10 +13,6 @@ IS_SPACES = os.getenv("SPACE_ID") is not None or os.getenv("HF_SPACE") is not No
|
|
| 13 |
# Add the current directory to Python path for Spaces environment
|
| 14 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 15 |
|
| 16 |
-
# Global flag to prevent duplicate initialization
|
| 17 |
-
_app_initialized = False
|
| 18 |
-
_demo_created = False
|
| 19 |
-
|
| 20 |
from openai import OpenAI
|
| 21 |
from src.config import Config
|
| 22 |
from src.vector_store import VectorStoreManager
|
|
@@ -241,68 +237,46 @@ def create_app():
|
|
| 241 |
|
| 242 |
# Create the app for Hugging Face Spaces
|
| 243 |
# Spaces will automatically detect Gradio and run this
|
| 244 |
-
#
|
| 245 |
-
|
| 246 |
-
# Initialize demo variable to None
|
| 247 |
-
demo = None
|
| 248 |
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
print(
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
demo = gr.Interface(
|
| 289 |
-
fn=show_error,
|
| 290 |
-
inputs=None,
|
| 291 |
-
outputs=gr.Markdown(),
|
| 292 |
-
title="CSRC Car Manual RAG System - Error",
|
| 293 |
-
description="An error occurred. Please check the logs."
|
| 294 |
-
)
|
| 295 |
-
_demo_created = True
|
| 296 |
-
else:
|
| 297 |
-
# App was initialized but demo not created (shouldn't happen)
|
| 298 |
-
print("β οΈ App initialized but demo not created, creating fallback...")
|
| 299 |
-
import gradio as gr
|
| 300 |
-
demo = gr.Interface(
|
| 301 |
-
fn=lambda: "App is initializing, please wait...",
|
| 302 |
-
inputs=None,
|
| 303 |
-
outputs="text",
|
| 304 |
-
title="CSRC Car Manual RAG System"
|
| 305 |
-
)
|
| 306 |
|
| 307 |
# Note: Do NOT call demo.launch() here
|
| 308 |
# Hugging Face Spaces will automatically detect and launch the demo
|
|
|
|
| 13 |
# Add the current directory to Python path for Spaces environment
|
| 14 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
from openai import OpenAI
|
| 17 |
from src.config import Config
|
| 18 |
from src.vector_store import VectorStoreManager
|
|
|
|
| 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 |
+
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
|
| 282 |
# Hugging Face Spaces will automatically detect and launch the demo
|