KarianaUMCP / core /config.py
barlowski's picture
Upload folder using huggingface_hub
22d587c verified
"""
Kariana Unified UI - Configuration Management
"""
import os
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class Config:
"""Configuration for Kariana Unified UI"""
# Server settings
gradio_port: int = 7860
gradio_host: str = "0.0.0.0"
# Unreal connection settings
unreal_port_range: tuple = (9877, 9887)
unreal_host: str = "localhost"
connection_timeout: float = 5.0
# Authentication
pin_length: int = 4
auth_enabled: bool = True
# Deployment mode
is_huggingface: bool = field(default_factory=lambda: os.getenv("SPACE_ID") is not None)
remote_mode: bool = False
# Logging
log_level: str = "INFO"
# Tunnel settings (for remote access)
ngrok_auth_token: Optional[str] = field(default_factory=lambda: os.getenv("NGROK_AUTH_TOKEN"))
tunnel_enabled: bool = False
@classmethod
def from_env(cls) -> "Config":
"""Create config from environment variables"""
return cls(
gradio_port=int(os.getenv("GRADIO_PORT", "7860")),
gradio_host=os.getenv("GRADIO_HOST", "0.0.0.0"),
unreal_host=os.getenv("UNREAL_HOST", "localhost"),
connection_timeout=float(os.getenv("CONNECTION_TIMEOUT", "5.0")),
auth_enabled=os.getenv("AUTH_ENABLED", "true").lower() == "true",
remote_mode=os.getenv("REMOTE_MODE", "false").lower() == "true",
log_level=os.getenv("LOG_LEVEL", "INFO"),
tunnel_enabled=os.getenv("TUNNEL_ENABLED", "false").lower() == "true",
)
def to_dict(self) -> dict:
"""Convert config to dictionary"""
return {
"gradio_port": self.gradio_port,
"gradio_host": self.gradio_host,
"unreal_port_range": self.unreal_port_range,
"unreal_host": self.unreal_host,
"connection_timeout": self.connection_timeout,
"pin_length": self.pin_length,
"auth_enabled": self.auth_enabled,
"is_huggingface": self.is_huggingface,
"remote_mode": self.remote_mode,
"log_level": self.log_level,
"tunnel_enabled": self.tunnel_enabled,
}