Spaces:
Running
Running
Commit
·
6fae15f
1
Parent(s):
d1171e9
Enhance application configuration: add MongoDB settings and directory management for audio, text, and temporary files, ensuring necessary directories are created at initialization.
Browse files- app/config.py +25 -3
- requirements.txt +1 -0
app/config.py
CHANGED
@@ -5,8 +5,22 @@ from pydantic_settings import BaseSettings
|
|
5 |
|
6 |
class Settings(BaseSettings):
|
7 |
"""Application settings."""
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
class Config:
|
12 |
"""Pydantic config."""
|
@@ -15,4 +29,12 @@ class Settings(BaseSettings):
|
|
15 |
@lru_cache()
|
16 |
def get_settings() -> Settings:
|
17 |
"""Get cached settings."""
|
18 |
-
return Settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
class Settings(BaseSettings):
|
7 |
"""Application settings."""
|
8 |
+
# MongoDB settings
|
9 |
+
MONGO_URI: str = os.getenv("MONGO_URI", "mongodb://localhost:27017")
|
10 |
+
DB_NAME: str = os.getenv("DB_NAME", "tts_api")
|
11 |
+
|
12 |
+
# Storage paths
|
13 |
+
STORAGE_PATH: str = os.getenv("STORAGE_PATH", "/app/storage")
|
14 |
+
AUDIO_DIR: str = os.path.join(STORAGE_PATH, "audio")
|
15 |
+
TEXT_DIR: str = os.path.join(STORAGE_PATH, "text")
|
16 |
+
TEMP_DIR: str = os.path.join(STORAGE_PATH, "temp")
|
17 |
+
|
18 |
+
# Ensure directories exist
|
19 |
+
def __init__(self, **kwargs):
|
20 |
+
super().__init__(**kwargs)
|
21 |
+
os.makedirs(self.AUDIO_DIR, exist_ok=True)
|
22 |
+
os.makedirs(self.TEXT_DIR, exist_ok=True)
|
23 |
+
os.makedirs(self.TEMP_DIR, exist_ok=True)
|
24 |
|
25 |
class Config:
|
26 |
"""Pydantic config."""
|
|
|
29 |
@lru_cache()
|
30 |
def get_settings() -> Settings:
|
31 |
"""Get cached settings."""
|
32 |
+
return Settings()
|
33 |
+
|
34 |
+
# Create settings instance
|
35 |
+
settings = get_settings()
|
36 |
+
|
37 |
+
# Export directory paths
|
38 |
+
AUDIO_DIR = settings.AUDIO_DIR
|
39 |
+
TEXT_DIR = settings.TEXT_DIR
|
40 |
+
TEMP_DIR = settings.TEMP_DIR
|
requirements.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
fastapi>=0.100.0
|
2 |
uvicorn>=0.24.0
|
3 |
pydantic>=2.4.0
|
|
|
4 |
python-multipart>=0.0.6
|
5 |
huggingface_hub>=0.20.0
|
6 |
torch>=2.0.0
|
|
|
1 |
fastapi>=0.100.0
|
2 |
uvicorn>=0.24.0
|
3 |
pydantic>=2.4.0
|
4 |
+
pydantic-settings>=2.1.0
|
5 |
python-multipart>=0.0.6
|
6 |
huggingface_hub>=0.20.0
|
7 |
torch>=2.0.0
|