Spaces:
Sleeping
Sleeping
| """ | |
| Configuration for Gradio + MCP Linux administration system. | |
| Simplified for Gradio's built-in MCP support. | |
| """ | |
| import os | |
| from typing import List | |
| from dataclasses import dataclass | |
| class OpenAIConfig: | |
| """OpenAI API configuration""" | |
| api_key: str | |
| model: str = "gpt-4o-mini" | |
| temperature: float = 0.7 | |
| max_tokens: int = 1000 | |
| def from_env(cls) -> 'OpenAIConfig': | |
| api_key = os.getenv('OPENAI_API_KEY') | |
| if not api_key: | |
| raise ValueError("OPENAI_API_KEY environment variable is required") | |
| return cls(api_key=api_key) | |
| class SecurityConfig: | |
| """Security settings for command execution""" | |
| # Whitelist of safe commands | |
| safe_commands: List[str] = None | |
| # Maximum command timeout (seconds) | |
| command_timeout: int = 30 | |
| def __post_init__(self): | |
| if self.safe_commands is None: | |
| self.safe_commands = [ | |
| "ls", "df", "cat", "ps", "whoami", "pwd", "date", | |
| "uptime", "free", "top", "netstat", "ss", | |
| "tail", "head", "grep", "find", "which" | |
| ] | |
| class GradioConfig: | |
| """Gradio interface configuration""" | |
| title: str = "Linux MCP Administration" | |
| description: str = "AI-powered Linux system administration with MCP tools" | |
| theme: str = "soft" | |
| share: bool = False | |
| # Chat interface settings | |
| chatbot_height: int = 600 | |
| textbox_placeholder: str = "Ask me about Linux administration..." | |
| class Config: | |
| """Main configuration class""" | |
| def __init__(self): | |
| self.openai = OpenAIConfig.from_env() | |
| self.security = SecurityConfig() | |
| self.gradio = GradioConfig() | |
| # Global config instance | |
| config = Config() |