|
|
""" |
|
|
μ± μ€μ νμΌ |
|
|
""" |
|
|
|
|
|
import os |
|
|
from dataclasses import dataclass |
|
|
from typing import Dict |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class AppConfig: |
|
|
"""μ± μ€μ ν΄λμ€""" |
|
|
|
|
|
|
|
|
app_name: str = "μμ± κ²μ¦ μμ€ν
" |
|
|
version: str = "1.0.0" |
|
|
|
|
|
|
|
|
stt_provider: str = os.getenv('STT_PROVIDER', 'mock') |
|
|
|
|
|
|
|
|
openai_api_key: str = os.getenv('OPENAI_API_KEY', '') |
|
|
openai_model: str = "whisper-1" |
|
|
|
|
|
|
|
|
google_credentials_path: str = os.getenv('GOOGLE_APPLICATION_CREDENTIALS', '') |
|
|
|
|
|
|
|
|
azure_speech_key: str = os.getenv('AZURE_SPEECH_KEY', '') |
|
|
azure_speech_region: str = os.getenv('AZURE_SPEECH_REGION', 'koreacentral') |
|
|
|
|
|
|
|
|
min_difficulty: int = 1 |
|
|
max_difficulty: int = 5 |
|
|
default_difficulty: int = 1 |
|
|
|
|
|
|
|
|
similarity_thresholds: Dict[int, float] = None |
|
|
|
|
|
|
|
|
theme: str = "soft" |
|
|
primary_color: str = "indigo" |
|
|
|
|
|
|
|
|
server_name: str = os.getenv("SERVER_HOST") |
|
|
server_port: int = os.getenv("FRONTEND_PORT") |
|
|
share: bool = False |
|
|
|
|
|
|
|
|
backend_port: int = os.getenv("BACKEND_PORT") |
|
|
backend_api_url: str = os.getenv("BACKEND_API_URL", "") |
|
|
|
|
|
|
|
|
max_audio_duration: int = 30 |
|
|
allowed_audio_formats: list = None |
|
|
|
|
|
def __post_init__(self): |
|
|
"""μ΄κΈ°ν ν μ²λ¦¬""" |
|
|
|
|
|
|
|
|
if self.similarity_thresholds is None: |
|
|
self.similarity_thresholds = { |
|
|
1: 0.70, |
|
|
2: 0.75, |
|
|
3: 0.80, |
|
|
4: 0.85, |
|
|
5: 0.90 |
|
|
} |
|
|
|
|
|
|
|
|
if self.allowed_audio_formats is None: |
|
|
self.allowed_audio_formats = [ |
|
|
'.wav', '.mp3', '.m4a', '.ogg', '.flac', '.webm' |
|
|
] |
|
|
|
|
|
@classmethod |
|
|
def from_env(cls): |
|
|
""" |
|
|
νκ²½ λ³μμμ μ€μ λ‘λ |
|
|
|
|
|
Returns: |
|
|
AppConfig: μ€μ μΈμ€ν΄μ€ |
|
|
""" |
|
|
backend_port = os.getenv('BACKEND_PORT') |
|
|
return cls( |
|
|
stt_provider=os.getenv('STT_PROVIDER', 'mock'), |
|
|
openai_api_key=os.getenv('OPENAI_API_KEY', ''), |
|
|
server_name=os.getenv('SERVER_HOST'), |
|
|
server_port=int(os.getenv('FRONTEND_PORT')), |
|
|
backend_port=int(backend_port), |
|
|
backend_api_url=os.getenv('BACKEND_API_URL', f'http://localhost:{backend_port}'), |
|
|
share=os.getenv('GRADIO_SHARE', 'false').lower() == 'true' |
|
|
) |
|
|
|
|
|
def validate(self) -> bool: |
|
|
""" |
|
|
μ€μ κ²μ¦ |
|
|
|
|
|
Returns: |
|
|
bool: μ ν¨ μ¬λΆ |
|
|
|
|
|
Raises: |
|
|
ValueError: μ€μ μ΄ μ ν¨νμ§ μμ λ |
|
|
""" |
|
|
|
|
|
if self.stt_provider == 'openai': |
|
|
if not self.openai_api_key: |
|
|
raise ValueError("OpenAI API ν€κ° μ€μ λμ§ μμμ΅λλ€") |
|
|
|
|
|
elif self.stt_provider == 'google': |
|
|
if not self.google_credentials_path: |
|
|
raise ValueError("Google μΈμ¦ νμΌ κ²½λ‘κ° μ€μ λμ§ μμμ΅λλ€") |
|
|
|
|
|
elif self.stt_provider == 'azure': |
|
|
if not self.azure_speech_key: |
|
|
raise ValueError("Azure Speech ν€κ° μ€μ λμ§ μμμ΅λλ€") |
|
|
|
|
|
|
|
|
if not (1 <= self.min_difficulty <= self.max_difficulty <= 5): |
|
|
raise ValueError("λμ΄λ λ²μκ° μ¬λ°λ₯΄μ§ μμ΅λλ€") |
|
|
|
|
|
return True |
|
|
|
|
|
def to_dict(self) -> dict: |
|
|
""" |
|
|
λμ
λλ¦¬λ‘ λ³ν |
|
|
|
|
|
Returns: |
|
|
dict: μ€μ λμ
λ리 |
|
|
""" |
|
|
return { |
|
|
'app_name': self.app_name, |
|
|
'version': self.version, |
|
|
'stt_provider': self.stt_provider, |
|
|
'difficulty_range': f"{self.min_difficulty}-{self.max_difficulty}", |
|
|
'server': f"{self.server_name}:{self.server_port}" |
|
|
} |
|
|
|
|
|
def __str__(self) -> str: |
|
|
"""λ¬Έμμ΄ νν""" |
|
|
config_dict = self.to_dict() |
|
|
lines = [f"{k}: {v}" for k, v in config_dict.items()] |
|
|
return "\n".join(lines) |
|
|
|