Spaces:
Runtime error
Runtime error
Implement environment-based UI launch configuration in main.py
Browse files- Added detection for running in Hugging Face Spaces using the SPACE_ID environment variable.
- Configured the UI launch to use '0.0.0.0' for server_name when in Hugging Face Spaces, and 'localhost' for local development.
- Maintained the server_port and share settings for both environments.
- src/main.py +18 -6
src/main.py
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
|
|
| 1 |
from src import parsers # Import all parsers to ensure they're registered
|
| 2 |
from src.ui.ui import launch_ui
|
| 3 |
|
| 4 |
def main():
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import os
|
| 2 |
from src import parsers # Import all parsers to ensure they're registered
|
| 3 |
from src.ui.ui import launch_ui
|
| 4 |
|
| 5 |
def main():
|
| 6 |
+
# Detect if running in Hugging Face Spaces
|
| 7 |
+
is_hf_space = os.getenv("SPACE_ID") is not None
|
| 8 |
+
|
| 9 |
+
if is_hf_space:
|
| 10 |
+
# Hugging Face Spaces configuration
|
| 11 |
+
launch_ui(
|
| 12 |
+
server_name="0.0.0.0",
|
| 13 |
+
server_port=7860,
|
| 14 |
+
share=False
|
| 15 |
+
)
|
| 16 |
+
else:
|
| 17 |
+
# Local development configuration
|
| 18 |
+
launch_ui(
|
| 19 |
+
server_name="localhost",
|
| 20 |
+
server_port=7860,
|
| 21 |
+
share=False
|
| 22 |
+
)
|
| 23 |
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|