Spaces:
Sleeping
Sleeping
Add test/deploy env args
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from loguru import logger
|
|
10 |
from Gradio_UI import GradioUI
|
11 |
from smolagents import LiteLLMModel
|
12 |
|
13 |
-
from config import setup_logger, load_api_keys, get_model_id,
|
14 |
from agents.manager_agent import create_manager_agent
|
15 |
|
16 |
|
@@ -35,12 +35,27 @@ def main():
|
|
35 |
|
36 |
# Start the Gradio UI server
|
37 |
logger.info("Initializing Gradio UI and launching server")
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
logger.success("Server started successfully")
|
45 |
|
46 |
|
|
|
10 |
from Gradio_UI import GradioUI
|
11 |
from smolagents import LiteLLMModel
|
12 |
|
13 |
+
from config import setup_logger, load_api_keys, get_model_id, get_gradio_config
|
14 |
from agents.manager_agent import create_manager_agent
|
15 |
|
16 |
|
|
|
35 |
|
36 |
# Start the Gradio UI server
|
37 |
logger.info("Initializing Gradio UI and launching server")
|
38 |
+
|
39 |
+
# Determine if we're in test mode (local) or production (HuggingFace)
|
40 |
+
# HuggingFace environment has SPACE_ID environment variable
|
41 |
+
import os
|
42 |
+
is_test = os.environ.get('SPACE_ID') is None
|
43 |
+
gradio_config = get_gradio_config(is_test)
|
44 |
+
|
45 |
+
# Launch with appropriate configuration
|
46 |
+
launch_kwargs = {
|
47 |
+
"debug": gradio_config["debug"],
|
48 |
+
"share": gradio_config["share"]
|
49 |
+
}
|
50 |
+
|
51 |
+
# Add server parameters only for local testing
|
52 |
+
if is_test:
|
53 |
+
launch_kwargs.update({
|
54 |
+
"server_name": gradio_config["server_name"],
|
55 |
+
"server_port": gradio_config["server_port"]
|
56 |
+
})
|
57 |
+
|
58 |
+
GradioUI(manager_agent).launch(**launch_kwargs)
|
59 |
logger.success("Server started successfully")
|
60 |
|
61 |
|
config.py
CHANGED
@@ -78,9 +78,28 @@ AGENT_CONFIG = {
|
|
78 |
}
|
79 |
|
80 |
# Gradio UI configuration
|
81 |
-
|
82 |
-
"
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
|
80 |
# Gradio UI configuration
|
81 |
+
def get_gradio_config(is_test=True):
|
82 |
+
"""Get the appropriate Gradio UI configuration based on environment.
|
83 |
+
|
84 |
+
Args:
|
85 |
+
is_test: If True, use test configuration (local development).
|
86 |
+
If False, use production configuration (HuggingFace).
|
87 |
+
|
88 |
+
Returns:
|
89 |
+
Dictionary with Gradio configuration parameters.
|
90 |
+
"""
|
91 |
+
if is_test:
|
92 |
+
# Configuration for local development/testing
|
93 |
+
return {
|
94 |
+
"debug": True,
|
95 |
+
"share": False,
|
96 |
+
"server_name": "127.0.0.1",
|
97 |
+
"server_port": 3000
|
98 |
+
}
|
99 |
+
else:
|
100 |
+
# Configuration for production (HuggingFace)
|
101 |
+
return {
|
102 |
+
"debug": True,
|
103 |
+
"share": False
|
104 |
+
# No server_name or server_port for HuggingFace deployment
|
105 |
+
}
|