Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 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
|
|
@@ -168,6 +167,15 @@ def create_app():
|
|
| 168 |
print("π CSRC Car Manual RAG System - Hugging Face Spaces")
|
| 169 |
print("=" * 60)
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
# Load configuration
|
| 172 |
config = Config()
|
| 173 |
|
|
@@ -214,7 +222,32 @@ def create_app():
|
|
| 214 |
proactive_engine=components["proactive_engine"]
|
| 215 |
)
|
| 216 |
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
return demo
|
| 219 |
|
| 220 |
|
|
@@ -257,36 +290,6 @@ except Exception as e:
|
|
| 257 |
description="An error occurred. Please check the logs."
|
| 258 |
)
|
| 259 |
|
| 260 |
-
#
|
| 261 |
-
#
|
| 262 |
-
|
| 263 |
-
import os
|
| 264 |
-
|
| 265 |
-
# Read the authentication information from the environment variable
|
| 266 |
-
auth_username = os.getenv("APP_USERNAME")
|
| 267 |
-
auth_password = os.getenv("APP_PASSWORD")
|
| 268 |
-
|
| 269 |
-
# If a username and password are set, authentication will be enabled
|
| 270 |
-
auth_config = None
|
| 271 |
-
if auth_username and auth_password:
|
| 272 |
-
auth_config = (auth_username, auth_password)
|
| 273 |
-
print(f"π Authentication enabled for user: {auth_username}")
|
| 274 |
-
else:
|
| 275 |
-
print("β οΈ No authentication configured. App is publicly accessible.")
|
| 276 |
-
|
| 277 |
-
print("π Launching Gradio app...")
|
| 278 |
-
|
| 279 |
-
try:
|
| 280 |
-
demo.launch(
|
| 281 |
-
share=False,
|
| 282 |
-
server_name="0.0.0.0",
|
| 283 |
-
server_port=7860,
|
| 284 |
-
auth=auth_config,
|
| 285 |
-
ssr_mode=False
|
| 286 |
-
)
|
| 287 |
-
print("β
App launched successfully!")
|
| 288 |
-
except Exception as e:
|
| 289 |
-
print(f"β Error launching app: {e}")
|
| 290 |
-
import traceback
|
| 291 |
-
traceback.print_exc()
|
| 292 |
-
|
|
|
|
| 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
|
|
|
|
| 167 |
print("π CSRC Car Manual RAG System - Hugging Face Spaces")
|
| 168 |
print("=" * 60)
|
| 169 |
|
| 170 |
+
# Check authentication settings
|
| 171 |
+
auth_username = os.getenv("APP_USERNAME")
|
| 172 |
+
auth_password = os.getenv("APP_PASSWORD")
|
| 173 |
+
|
| 174 |
+
if auth_username and auth_password:
|
| 175 |
+
print(f"π Authentication enabled for user: {auth_username}")
|
| 176 |
+
else:
|
| 177 |
+
print("β οΈ No authentication configured. App is publicly accessible.")
|
| 178 |
+
|
| 179 |
# Load configuration
|
| 180 |
config = Config()
|
| 181 |
|
|
|
|
| 222 |
proactive_engine=components["proactive_engine"]
|
| 223 |
)
|
| 224 |
|
| 225 |
+
# Create interface with authentication
|
| 226 |
+
auth_config = None
|
| 227 |
+
if auth_username and auth_password:
|
| 228 |
+
auth_config = (auth_username, auth_password)
|
| 229 |
+
|
| 230 |
+
demo = interface_builder.create_interface(auth=auth_config)
|
| 231 |
+
|
| 232 |
+
# Set authentication for Hugging Face Spaces
|
| 233 |
+
# In Gradio 6.0+, we can use demo.auth or configure it during launch
|
| 234 |
+
# Since Spaces auto-launches, we set it here so Spaces can use it
|
| 235 |
+
if auth_config:
|
| 236 |
+
try:
|
| 237 |
+
# Method 1: Try setting auth attribute directly (Gradio 6.0+)
|
| 238 |
+
if hasattr(demo, 'auth'):
|
| 239 |
+
demo.auth = auth_config
|
| 240 |
+
print("β
Authentication configured via demo.auth")
|
| 241 |
+
else:
|
| 242 |
+
# Method 2: Use launch configuration
|
| 243 |
+
# Store auth config to be used when Spaces launches
|
| 244 |
+
demo._auth = auth_config
|
| 245 |
+
print("β
Authentication configured (will be applied on launch)")
|
| 246 |
+
except Exception as e:
|
| 247 |
+
print(f"β οΈ Error setting auth: {e}")
|
| 248 |
+
# Fallback: store in custom attribute
|
| 249 |
+
demo._auth_config = auth_config
|
| 250 |
+
|
| 251 |
return demo
|
| 252 |
|
| 253 |
|
|
|
|
| 290 |
description="An error occurred. Please check the logs."
|
| 291 |
)
|
| 292 |
|
| 293 |
+
# Note: Do NOT call demo.launch() here
|
| 294 |
+
# Hugging Face Spaces will automatically detect and launch the demo
|
| 295 |
+
# The demo variable is exposed at module level, which is what Spaces expects
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|