krislette commited on
Commit
87d96e9
·
1 Parent(s): e26dafd

Auto-deploy from GitHub: 9fdfbb96df26a648c04acf60b01afa1826adf83b

Browse files
app/server.py CHANGED
@@ -10,7 +10,7 @@ from app.schemas import (
10
  PredictionXAIResponse,
11
  WelcomeResponse,
12
  )
13
- from app.utils import load_config, download_youtube_audio
14
 
15
  # Model/XAI-related imports
16
  from scripts.explain import musiclime
@@ -22,19 +22,22 @@ import librosa
22
  from typing import Optional, Tuple
23
 
24
 
25
- # Load config at startup
26
- config = load_config()
 
27
 
28
  # Extract configuration values
29
- MAX_FILE_SIZE = config["file_upload"]["max_file_size_mb"] * 1024 * 1024
30
- MAX_LYRICS_LENGTH = config["file_upload"]["max_lyrics_length"]
31
- ALLOWED_AUDIO_TYPES = config["file_upload"]["allowed_audio_types"]
32
 
33
  # Initialize fast API app with extracted config values
34
- app = FastAPI(title=config["server"]["title"], version=config["server"]["version"])
 
 
35
 
36
  # Initialize CORS with config values
37
- cors_config = config["api"]["cors"]
38
  app.add_middleware(
39
  CORSMiddleware,
40
  allow_origins=cors_config["allow_origins"],
@@ -210,19 +213,23 @@ async def get_model_info():
210
  # Get supported formats from config
211
  supported_formats = [fmt.replace("audio/", "") for fmt in ALLOWED_AUDIO_TYPES]
212
 
 
 
 
 
213
  return ModelInfoResponse(
214
  status="success",
215
  message="Model information retrieved successfully",
216
- model_name="Bach or Bot",
217
- model_version="1.0.0", # TODO: Load from model metadata when available
218
  supported_formats=supported_formats,
219
- max_file_size_mb=config["file_upload"]["max_file_size_mb"],
220
  training_info={
221
- "dataset": "Human-Composed and AI-generated music samples",
222
- "architecture": "To be specified", # TODO: Update when model is implemented
223
- "accuracy": "To be determined", # TODO: Update with actual metrics
224
  },
225
- last_updated="2024-01-01T00:00:00Z", # TODO: Update with actual timestamp
226
  )
227
 
228
  except Exception as e:
 
10
  PredictionXAIResponse,
11
  WelcomeResponse,
12
  )
13
+ from app.utils import load_server_config, load_model_config, download_youtube_audio
14
 
15
  # Model/XAI-related imports
16
  from scripts.explain import musiclime
 
22
  from typing import Optional, Tuple
23
 
24
 
25
+ # Load configs at startup
26
+ server_config = load_server_config()
27
+ model_config = load_model_config()
28
 
29
  # Extract configuration values
30
+ MAX_FILE_SIZE = server_config["file_upload"]["max_file_size_mb"] * 1024 * 1024
31
+ MAX_LYRICS_LENGTH = server_config["file_upload"]["max_lyrics_length"]
32
+ ALLOWED_AUDIO_TYPES = server_config["file_upload"]["allowed_audio_types"]
33
 
34
  # Initialize fast API app with extracted config values
35
+ app = FastAPI(
36
+ title=server_config["server"]["title"], version=server_config["server"]["version"]
37
+ )
38
 
39
  # Initialize CORS with config values
40
+ cors_config = server_config["api"]["cors"]
41
  app.add_middleware(
42
  CORSMiddleware,
43
  allow_origins=cors_config["allow_origins"],
 
213
  # Get supported formats from config
214
  supported_formats = [fmt.replace("audio/", "") for fmt in ALLOWED_AUDIO_TYPES]
215
 
216
+ # Get model info from config
217
+ model_metadata = model_config["metadata"]
218
+ model_architecture = model_config["mlp"]
219
+
220
  return ModelInfoResponse(
221
  status="success",
222
  message="Model information retrieved successfully",
223
+ model_name=model_metadata["name"],
224
+ model_version=model_metadata["version"],
225
  supported_formats=supported_formats,
226
+ max_file_size_mb=server_config["file_upload"]["max_file_size_mb"],
227
  training_info={
228
+ "dataset": model_metadata["dataset"],
229
+ "architecture": f"{model_metadata['architecture']} - Layers: {model_architecture['hidden_layers']}",
230
+ "accuracy": model_metadata["accuracy"],
231
  },
232
+ last_updated=model_metadata["last_updated"],
233
  )
234
 
235
  except Exception as e:
app/utils.py CHANGED
@@ -9,7 +9,7 @@ from pathlib import Path
9
  from yt_dlp.utils import DownloadError
10
 
11
 
12
- def load_config():
13
  """
14
  Load server configs from YAML file.
15
  """
@@ -23,6 +23,19 @@ def load_config():
23
  return yaml.safe_load(file)
24
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  def download_youtube_audio(youtube_url: str) -> bytes:
27
  """
28
  Download audio from YouTube URL and return as bytes.
 
9
  from yt_dlp.utils import DownloadError
10
 
11
 
12
+ def load_server_config():
13
  """
14
  Load server configs from YAML file.
15
  """
 
23
  return yaml.safe_load(file)
24
 
25
 
26
+ def load_model_config():
27
+ """
28
+ Load model configs from YAML file.
29
+ """
30
+ config_path = Path(__file__).parent.parent / "config" / "model_config.yml"
31
+
32
+ if not config_path.exists():
33
+ raise FileNotFoundError(f"Configuration file not found : {config_path}")
34
+
35
+ with open(config_path, "r") as file:
36
+ return yaml.safe_load(file)
37
+
38
+
39
  def download_youtube_audio(youtube_url: str) -> bytes:
40
  """
41
  Download audio from YouTube URL and return as bytes.
config/model_config.yml CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
  mlp:
2
  hidden_layers: [512, 256, 128] # 3 hidden layers
3
  dropout: [0.5, 0.4, 0.3] # Dropout rates for each layer
 
1
+ # Model Metadata (for API infor endpoint)
2
+ metadata:
3
+ name: "Bach or Bot"
4
+ version: "1.0.0"
5
+ architecture: "Multi-Layer Perceptron (MLP)"
6
+ dataset: "SONICS: Real vs Fake Songs Detection Dataset"
7
+ accuracy: "97%"
8
+ last_updated: "2025-10-06"
9
+
10
  mlp:
11
  hidden_layers: [512, 256, 128] # 3 hidden layers
12
  dropout: [0.5, 0.4, 0.3] # Dropout rates for each layer
config/server_config.yml CHANGED
@@ -18,8 +18,12 @@ file_upload:
18
  # API Configuration
19
  api:
20
  cors:
21
- # TODO: Change to specific origins in production
22
- allow_origins: ["*"]
23
- allow_credentials: true
24
- allow_methods: ["*"]
25
- allow_headers: ["*"]
 
 
 
 
 
18
  # API Configuration
19
  api:
20
  cors:
21
+ allow_origins:
22
+ - "http://localhost:5173"
23
+ - "https://bach-or-bot.vercel.app"
24
+ allow_credentials: false
25
+ allow_methods:
26
+ - "GET"
27
+ - "POST"
28
+ allow_headers:
29
+ - "Content-Type"