James Edmunds commited on
Commit ·
392cdf6
1
Parent(s): a63d501
fixing paths
Browse files- config/settings.py +34 -23
- src/generator/generator.py +8 -0
config/settings.py
CHANGED
|
@@ -4,38 +4,30 @@ from dotenv import load_dotenv
|
|
| 4 |
|
| 5 |
load_dotenv()
|
| 6 |
|
| 7 |
-
# Get base project directory
|
| 8 |
-
BASE_DIR = Path(__file__).parent.parent
|
| 9 |
-
|
| 10 |
class Settings:
|
|
|
|
|
|
|
|
|
|
| 11 |
# Deployment Mode
|
| 12 |
-
DEPLOYMENT_MODE = os.getenv('DEPLOYMENT_MODE', 'local')
|
| 13 |
|
| 14 |
# API Keys
|
| 15 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 16 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 17 |
|
| 18 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
LYRICS_DIR = BASE_DIR / "data" / "raw" / "lyrics"
|
| 20 |
EMBEDDINGS_DIR = BASE_DIR / "data" / "processed" / "embeddings"
|
|
|
|
| 21 |
|
| 22 |
# Model Settings
|
| 23 |
EMBEDDING_MODEL = "text-embedding-ada-002"
|
| 24 |
LLM_MODEL = "gpt-4"
|
| 25 |
|
| 26 |
-
# ChromaDB Settings
|
| 27 |
-
@classmethod
|
| 28 |
-
def get_chroma_settings(cls) -> dict:
|
| 29 |
-
"""Get ChromaDB settings based on deployment mode"""
|
| 30 |
-
return {
|
| 31 |
-
"anonymized_telemetry": False,
|
| 32 |
-
"persist_directory": str(cls.get_embeddings_path() / "chroma")
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
# HuggingFace Settings
|
| 36 |
-
HF_SPACE = "SongLift/LyrGen2"
|
| 37 |
-
HF_DATASET = "SongLift/LyrGen2_DB"
|
| 38 |
-
|
| 39 |
@classmethod
|
| 40 |
def is_huggingface(cls) -> bool:
|
| 41 |
"""Check if running in HuggingFace environment"""
|
|
@@ -43,10 +35,29 @@ class Settings:
|
|
| 43 |
|
| 44 |
@classmethod
|
| 45 |
def get_embeddings_path(cls) -> Path:
|
| 46 |
-
"""Get
|
| 47 |
if cls.is_huggingface():
|
| 48 |
-
# Use absolute path
|
| 49 |
return Path("/data/processed/embeddings")
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
load_dotenv()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
class Settings:
|
| 8 |
+
# Base Paths
|
| 9 |
+
BASE_DIR = Path(__file__).parent.parent
|
| 10 |
+
|
| 11 |
# Deployment Mode
|
| 12 |
+
DEPLOYMENT_MODE = os.getenv('DEPLOYMENT_MODE', 'local')
|
| 13 |
|
| 14 |
# API Keys
|
| 15 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 16 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 17 |
|
| 18 |
+
# HuggingFace Settings
|
| 19 |
+
HF_SPACE = "SongLift/LyrGen2"
|
| 20 |
+
HF_DATASET = "SongLift/LyrGen2_DB"
|
| 21 |
+
|
| 22 |
+
# Local Settings
|
| 23 |
LYRICS_DIR = BASE_DIR / "data" / "raw" / "lyrics"
|
| 24 |
EMBEDDINGS_DIR = BASE_DIR / "data" / "processed" / "embeddings"
|
| 25 |
+
CHROMA_DIR = EMBEDDINGS_DIR / "chroma"
|
| 26 |
|
| 27 |
# Model Settings
|
| 28 |
EMBEDDING_MODEL = "text-embedding-ada-002"
|
| 29 |
LLM_MODEL = "gpt-4"
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
@classmethod
|
| 32 |
def is_huggingface(cls) -> bool:
|
| 33 |
"""Check if running in HuggingFace environment"""
|
|
|
|
| 35 |
|
| 36 |
@classmethod
|
| 37 |
def get_embeddings_path(cls) -> Path:
|
| 38 |
+
"""Get the base embeddings path"""
|
| 39 |
if cls.is_huggingface():
|
| 40 |
+
# HuggingFace: Use absolute path in persistent storage
|
| 41 |
return Path("/data/processed/embeddings")
|
| 42 |
+
# Local: Use project-relative path
|
| 43 |
+
return cls.BASE_DIR / "data" / "processed" / "embeddings"
|
| 44 |
+
|
| 45 |
+
@classmethod
|
| 46 |
+
def get_chroma_path(cls) -> Path:
|
| 47 |
+
"""Get the Chroma DB path"""
|
| 48 |
+
return cls.get_embeddings_path() / "chroma"
|
| 49 |
+
|
| 50 |
+
@classmethod
|
| 51 |
+
def ensure_embedding_paths(cls) -> None:
|
| 52 |
+
"""Ensure all embedding-related directories exist"""
|
| 53 |
+
if not cls.is_huggingface(): # Only create directories locally
|
| 54 |
+
cls.get_embeddings_path().mkdir(parents=True, exist_ok=True)
|
| 55 |
+
cls.get_chroma_path().mkdir(parents=True, exist_ok=True)
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def get_chroma_settings(cls) -> dict:
|
| 59 |
+
"""Get ChromaDB settings"""
|
| 60 |
+
return {
|
| 61 |
+
"anonymized_telemetry": False,
|
| 62 |
+
"persist_directory": str(cls.get_chroma_path())
|
| 63 |
+
}
|
src/generator/generator.py
CHANGED
|
@@ -13,8 +13,16 @@ class LyricGenerator:
|
|
| 13 |
def __init__(self):
|
| 14 |
"""Initialize the generator with embeddings"""
|
| 15 |
print("Initializing LyricGenerator...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
self.embeddings_dir = Settings.get_embeddings_path()
|
|
|
|
| 17 |
print(f"Embeddings directory: {self.embeddings_dir}")
|
|
|
|
| 18 |
|
| 19 |
# Initialize OpenAI embeddings
|
| 20 |
print("Setting up OpenAI embeddings...")
|
|
|
|
| 13 |
def __init__(self):
|
| 14 |
"""Initialize the generator with embeddings"""
|
| 15 |
print("Initializing LyricGenerator...")
|
| 16 |
+
print(f"Deployment mode: {Settings.DEPLOYMENT_MODE}")
|
| 17 |
+
|
| 18 |
+
# Ensure paths exist (if local)
|
| 19 |
+
Settings.ensure_embedding_paths()
|
| 20 |
+
|
| 21 |
+
# Get and log paths
|
| 22 |
self.embeddings_dir = Settings.get_embeddings_path()
|
| 23 |
+
self.chroma_dir = Settings.get_chroma_path()
|
| 24 |
print(f"Embeddings directory: {self.embeddings_dir}")
|
| 25 |
+
print(f"Chroma directory: {self.chroma_dir}")
|
| 26 |
|
| 27 |
# Initialize OpenAI embeddings
|
| 28 |
print("Setting up OpenAI embeddings...")
|