Shim commited on
Commit Β·
37545aa
1
Parent(s): 77244ea
Unify local and HF Spaces experience with improved launch configuration
Browse files
app.py
CHANGED
|
@@ -529,28 +529,40 @@ def main():
|
|
| 529 |
app = MirautrApp()
|
| 530 |
demo = app.create_main_interface()
|
| 531 |
|
| 532 |
-
#
|
| 533 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
| 534 |
|
| 535 |
logger.info(f"Launching app... HF Spaces: {is_hf_spaces}")
|
| 536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
if is_hf_spaces:
|
| 538 |
-
# HF Spaces
|
| 539 |
logger.info("Configuring for HF Spaces deployment")
|
| 540 |
-
|
| 541 |
-
server_name
|
| 542 |
-
server_port
|
| 543 |
-
|
| 544 |
-
quiet
|
| 545 |
-
)
|
| 546 |
else:
|
| 547 |
-
# Local development
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
|
|
|
|
|
|
|
|
|
| 554 |
|
| 555 |
except Exception as e:
|
| 556 |
logger.error(f"Failed to start application: {e}")
|
|
|
|
| 529 |
app = MirautrApp()
|
| 530 |
demo = app.create_main_interface()
|
| 531 |
|
| 532 |
+
# Check environment
|
| 533 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
| 534 |
|
| 535 |
logger.info(f"Launching app... HF Spaces: {is_hf_spaces}")
|
| 536 |
|
| 537 |
+
# Unified launch configuration for both environments
|
| 538 |
+
# This ensures identical experience in both local and HF Spaces
|
| 539 |
+
launch_config = {
|
| 540 |
+
"show_error": True,
|
| 541 |
+
"show_api": False, # Disable API docs to avoid schema issues
|
| 542 |
+
"favicon_path": None,
|
| 543 |
+
"auth": None
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
if is_hf_spaces:
|
| 547 |
+
# HF Spaces specific settings
|
| 548 |
logger.info("Configuring for HF Spaces deployment")
|
| 549 |
+
launch_config.update({
|
| 550 |
+
"server_name": "0.0.0.0",
|
| 551 |
+
"server_port": 7860,
|
| 552 |
+
"share": False, # HF Spaces handles public access
|
| 553 |
+
"quiet": True
|
| 554 |
+
})
|
| 555 |
else:
|
| 556 |
+
# Local development settings
|
| 557 |
+
logger.info("Configuring for local development")
|
| 558 |
+
launch_config.update({
|
| 559 |
+
"server_name": "127.0.0.1",
|
| 560 |
+
"server_port": int(os.getenv("GRADIO_SERVER_PORT", "7860")),
|
| 561 |
+
"share": True, # Create public link for local testing
|
| 562 |
+
"quiet": False
|
| 563 |
+
})
|
| 564 |
+
|
| 565 |
+
demo.launch(**launch_config)
|
| 566 |
|
| 567 |
except Exception as e:
|
| 568 |
logger.error(f"Failed to start application: {e}")
|