OnyxMunk/AudioForge
0
1#!/usr/bin/env python3
2"""
3AudioForge Environment Setup Script
4Helps configure .env file with Hugging Face token and other settings
5"""
6
7import os
8import sys
9from pathlib import Path
10from typing import Optional
11
12def get_input(prompt: str, default: Optional[str] = None, required: bool = False) -> str:
13 """Get user input with optional default value."""
14 if default:
15 prompt = f"{prompt} [{default}]: "
16 else:
17 prompt = f"{prompt}: "
18
19 while True:
20 value = input(prompt).strip()
21 if not value and default:
22 return default
23 if not value and required:
24 print("โ This field is required!")
25 continue
26 return value
27
28
29def generate_secret_key() -> str:
30 """Generate a secure random secret key."""
31 import secrets
32 return secrets.token_urlsafe(32)
33
34
35def main():
36 """Main setup function."""
37 print("๐ต AudioForge Environment Setup")
38 print("=" * 60)
39 print()
40
41 # Determine paths
42 script_dir = Path(__file__).parent
43 project_root = script_dir.parent
44 backend_dir = project_root / "backend"
45 env_file = backend_dir / ".env"
46 env_example = backend_dir / ".env.example"
47
48 # Check if .env already exists
49 if env_file.exists():
50 print(f"โ ๏ธ .env file already exists at: {env_file}")
51 overwrite = get_input("Do you want to overwrite it? (yes/no)", default="no")
52 if overwrite.lower() not in ["yes", "y"]:
53 print("โ Setup cancelled.")
54 sys.exit(0)
55 print()
56
57 print("๐ Let's configure your environment variables...")
58 print()
59
60 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
61 # Hugging Face Token (MOST IMPORTANT)
62 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
63 print("๐ค HUGGING FACE TOKEN (REQUIRED)")
64 print("-" * 60)
65 print("You need a Hugging Face token to download AI models.")
66 print("Get your token from: https://huggingface.co/settings/tokens")
67 print()
68
69 hf_token = get_input(
70 "Enter your Hugging Face token",
71 required=True
72 )
73 print()
74
75 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
76 # Environment Type
77 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
78 print("๐ ENVIRONMENT TYPE")
79 print("-" * 60)
80 environment = get_input(
81 "Environment (development/staging/production)",
82 default="development"
83 )
84 print()
85
86 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
87 # Database Configuration
88 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
89 print("๐๏ธ DATABASE CONFIGURATION")
90 print("-" * 60)
91
92 if environment == "production":
93 # Production: User should provide their production database URL
94 # Default shown is for reference only
95 database_url = get_input(
96 "Database URL",
97 default="postgresql+asyncpg://postgres:postgres@localhost:5432/audioforge",
98 required=True
99 )
100 else:
101 # Development uses Docker port 5433 (mapped from container's 5432)
102 database_url = "postgresql+asyncpg://postgres:postgres@localhost:5433/audioforge"
103 print(f"Using default: {database_url}")
104 print(" (Docker container exposes PostgreSQL on port 5433)")
105 print()
106
107 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
108 # Redis Configuration
109 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
110 print("๐ฆ REDIS CONFIGURATION")
111 print("-" * 60)
112 redis_url = get_input(
113 "Redis URL",
114 default="redis://localhost:6379/0"
115 )
116 print()
117
118 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
119 # Device Configuration
120 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
121 print("๐ฅ๏ธ DEVICE CONFIGURATION")
122 print("-" * 60)
123 print("Device options: cpu, cuda (NVIDIA GPU), mps (Apple Silicon)")
124
125 # Check if CUDA is available
126 try:
127 import torch
128 if torch.cuda.is_available():
129 print("โ
CUDA detected! GPU acceleration available.")
130 default_device = "cuda"
131 else:
132 print("โน๏ธ No CUDA detected. Using CPU.")
133 default_device = "cpu"
134 except ImportError:
135 print("โน๏ธ PyTorch not installed yet. Defaulting to CPU.")
136 default_device = "cpu"
137
138 device = get_input(
139 "Device for AI models",
140 default=default_device
141 )
142 print()
143
144 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
145 # CORS Configuration
146 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
147 print("๐ CORS CONFIGURATION")
148 print("-" * 60)
149
150 if environment == "production":
151 allowed_origins = get_input(
152 "Allowed origins (comma-separated)",
153 default="https://yourdomain.com"
154 )
155 else:
156 allowed_origins = "http://localhost:3000,http://localhost:3001"
157 print(f"Using default: {allowed_origins}")
158 print()
159
160 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
161 # Secret Key
162 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
163 print("๐ SECRET KEY")
164 print("-" * 60)
165 secret_key = generate_secret_key()
166 print(f"Generated secure secret key: {secret_key[:20]}...")
167 print()
168
169 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
170 # Generate .env file
171 # โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
172 print("๐ Generating .env file...")
173
174 env_content = f"""# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
175# AudioForge Backend Environment Configuration
176# Generated by setup_env.py on {Path(__file__).stat().st_mtime}
177# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
178
179# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
180# Application Settings
181# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
182DEBUG={'true' if environment == 'development' else 'false'}
183ENVIRONMENT={environment}
184LOG_LEVEL={'DEBUG' if environment == 'development' else 'INFO'}
185SECRET_KEY={secret_key}
186
187# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
188# Database Configuration
189# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
190DATABASE_URL={database_url}
191
192# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
193# Redis Configuration
194# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
195REDIS_URL={redis_url}
196
197# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
198# AI Models Configuration
199# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
200
201# Hugging Face Token (REQUIRED)
202HUGGINGFACE_TOKEN={hf_token}
203HF_TOKEN={hf_token}
204
205# Device configuration
206MUSICGEN_DEVICE={device}
207BARK_DEVICE={device}
208DEMUCS_DEVICE={device}
209
210# Model versions
211MUSICGEN_MODEL=facebook/musicgen-small
212BARK_MODEL=suno/bark-small
213DEMUCS_MODEL=htdemucs
214
215# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
216# API Configuration
217# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
218API_V1_PREFIX=/api/v1
219ALLOWED_ORIGINS={allowed_origins}
220
221# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
222# Audio Processing Settings
223# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
224MAX_AUDIO_DURATION=300
225DEFAULT_AUDIO_DURATION=30
226AUDIO_SAMPLE_RATE=32000
227
228# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
229# Feature Flags
230# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
231ENABLE_VOCALS=true
232ENABLE_MASTERING=true
233ENABLE_STEM_SEPARATION=true
234
235# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
236# Monitoring (Optional)
237# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
238ENABLE_METRICS=true
239
240# Sentry (uncomment and configure if needed)
241# SENTRY_DSN=your-sentry-dsn
242# SENTRY_ENVIRONMENT={environment}
243"""
244
245 # Write .env file
246 env_file.write_text(env_content, encoding="utf-8")
247
248 print("โ
.env file created successfully!")
249 print()
250 print("=" * 60)
251 print("๐ Setup Complete!")
252 print("=" * 60)
253 print()
254 print(f"๐ Configuration saved to: {env_file}")
255 print()
256 print("๐ Next Steps:")
257 print(" 1. Review the .env file and adjust if needed")
258 print(" 2. Install dependencies: cd backend && pip install -e '.[dev]'")
259 print(" 3. Initialize database: python scripts/init_db.py")
260 print(" 4. Start the backend: uvicorn app.main:app --reload")
261 print()
262 print("๐ค Your Hugging Face token is configured!")
263 print(" Models will download automatically on first use.")
264 print()
265 print("๐ผโก Ready to forge some audio!")
266
267
268if __name__ == "__main__":
269 try:
270 main()
271 except KeyboardInterrupt:
272 print("\n\nโ Setup cancelled by user.")
273 sys.exit(1)
274 except Exception as e:
275 print(f"\n\nโ Error during setup: {e}")
276 sys.exit(1)
277 