Spaces:
Running
Running
zach
commited on
Commit
·
58de40c
1
Parent(s):
7adf034
Add config file for loading env vars and logger setup
Browse files
config.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
config.py
|
3 |
+
|
4 |
+
Global configuration and logger setup for the project. This file centralizes shared
|
5 |
+
constants and settings, such as the logging configuration and API constraints.
|
6 |
+
|
7 |
+
Key Features:
|
8 |
+
- Configures the logger for consistent logging across all modules.
|
9 |
+
- Dynamically sets the logging level based on the DEBUG environment variable.
|
10 |
+
- Provides constants for shared constraints like maximum prompt length.
|
11 |
+
|
12 |
+
Constants:
|
13 |
+
- DEBUG: Indicates whether debug mode is enabled.
|
14 |
+
"""
|
15 |
+
|
16 |
+
# Standard Library Imports
|
17 |
+
import logging
|
18 |
+
import os
|
19 |
+
# Third-Party Library Imports
|
20 |
+
from dotenv import load_dotenv
|
21 |
+
|
22 |
+
|
23 |
+
# Load environment variables
|
24 |
+
load_dotenv()
|
25 |
+
|
26 |
+
|
27 |
+
# Enable debugging mode based on an environment variable
|
28 |
+
debug_raw = os.getenv("DEBUG", "false").lower()
|
29 |
+
if debug_raw not in {"true", "false"}:
|
30 |
+
print(f"Warning: Invalid DEBUG value '{debug_raw}'. Defaulting to 'false'.")
|
31 |
+
DEBUG = debug_raw == "true"
|
32 |
+
|
33 |
+
|
34 |
+
# Configure the logger
|
35 |
+
logging.basicConfig(
|
36 |
+
level=logging.DEBUG if DEBUG else logging.INFO,
|
37 |
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
38 |
+
)
|
39 |
+
logger: logging.Logger = logging.getLogger("tts_arena")
|
40 |
+
logger.info(f"Debug mode is {'enabled' if DEBUG else 'disabled'}.")
|
41 |
+
|
42 |
+
|
43 |
+
# Log environment variables
|
44 |
+
def log_env_variable(var_name: str, value: str) -> None:
|
45 |
+
"""
|
46 |
+
Logs the value of an environment variable for debugging purposes.
|
47 |
+
|
48 |
+
Args:
|
49 |
+
var_name (str): The name of the environment variable.
|
50 |
+
value (str): The value of the environment variable.
|
51 |
+
"""
|
52 |
+
logger.debug(f"Environment variable '{var_name}' validated with value: {value}")
|
53 |
+
|
54 |
+
log_env_variable("DEBUG", str(DEBUG))
|