Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -260,11 +260,15 @@ def create_app():
|
|
| 260 |
|
| 261 |
# Create the app for Hugging Face Spaces
|
| 262 |
# Spaces will automatically detect Gradio and run this
|
| 263 |
-
# Use global flag to prevent duplicate initialization
|
|
|
|
|
|
|
| 264 |
if not _app_initialized:
|
| 265 |
_app_initialized = True
|
| 266 |
try:
|
| 267 |
-
|
|
|
|
|
|
|
| 268 |
print("β
App created successfully!")
|
| 269 |
print(f"β
Demo type: {type(demo)}")
|
| 270 |
except Exception as e:
|
|
@@ -292,21 +296,30 @@ if not _app_initialized:
|
|
| 292 |
```
|
| 293 |
"""
|
| 294 |
|
| 295 |
-
|
| 296 |
fn=show_error,
|
| 297 |
inputs=None,
|
| 298 |
outputs=gr.Markdown(),
|
| 299 |
title="CSRC Car Manual RAG System - Error",
|
| 300 |
description="An error occurred. Please check the logs."
|
| 301 |
)
|
|
|
|
| 302 |
else:
|
| 303 |
-
# If already initialized,
|
| 304 |
-
print("β οΈ App already initialized,
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
| 307 |
# Fallback: create a simple demo if somehow not defined
|
|
|
|
| 308 |
import gradio as gr
|
| 309 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
# Note: Do NOT call demo.launch() here
|
| 312 |
# Hugging Face Spaces will automatically detect and launch the demo
|
|
|
|
| 260 |
|
| 261 |
# Create the app for Hugging Face Spaces
|
| 262 |
# Spaces will automatically detect Gradio and run this
|
| 263 |
+
# Use global flag and module-level demo variable to prevent duplicate initialization
|
| 264 |
+
_demo_instance = None
|
| 265 |
+
|
| 266 |
if not _app_initialized:
|
| 267 |
_app_initialized = True
|
| 268 |
try:
|
| 269 |
+
print("π Starting app initialization (first time)...")
|
| 270 |
+
_demo_instance = create_app()
|
| 271 |
+
demo = _demo_instance # Expose to module level for Spaces
|
| 272 |
print("β
App created successfully!")
|
| 273 |
print(f"β
Demo type: {type(demo)}")
|
| 274 |
except Exception as e:
|
|
|
|
| 296 |
```
|
| 297 |
"""
|
| 298 |
|
| 299 |
+
_demo_instance = gr.Interface(
|
| 300 |
fn=show_error,
|
| 301 |
inputs=None,
|
| 302 |
outputs=gr.Markdown(),
|
| 303 |
title="CSRC Car Manual RAG System - Error",
|
| 304 |
description="An error occurred. Please check the logs."
|
| 305 |
)
|
| 306 |
+
demo = _demo_instance
|
| 307 |
else:
|
| 308 |
+
# If already initialized, reuse the existing demo
|
| 309 |
+
print("β οΈ App already initialized, reusing existing demo instance")
|
| 310 |
+
if _demo_instance is not None:
|
| 311 |
+
demo = _demo_instance
|
| 312 |
+
print("β
Reusing previously created demo")
|
| 313 |
+
else:
|
| 314 |
# Fallback: create a simple demo if somehow not defined
|
| 315 |
+
print("β οΈ No demo instance found, creating fallback...")
|
| 316 |
import gradio as gr
|
| 317 |
+
demo = gr.Interface(
|
| 318 |
+
fn=lambda: "App is initializing, please wait...",
|
| 319 |
+
inputs=None,
|
| 320 |
+
outputs="text",
|
| 321 |
+
title="CSRC Car Manual RAG System"
|
| 322 |
+
)
|
| 323 |
|
| 324 |
# Note: Do NOT call demo.launch() here
|
| 325 |
# Hugging Face Spaces will automatically detect and launch the demo
|