vectorverse commited on
Commit
11c8e8e
Β·
verified Β·
1 Parent(s): bd43bae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -4,8 +4,8 @@ import librosa
4
  import numpy as np
5
  from transformers import ASTFeatureExtractor, ASTForAudioClassification
6
 
7
- # ── CONFIG ──────────────────────────────────────────────────────────────────
8
- HF_REPO = "kashishvijayvergiya/music-genre-ast" # your HF repo
9
  SAMPLE_RATE = 16000
10
  DURATION = 20
11
  MAX_LENGTH = SAMPLE_RATE * DURATION
@@ -21,7 +21,7 @@ GENRE_EMOJI = {
21
  "reggae": "🌴", "rock": "πŸ”₯"
22
  }
23
 
24
- # ── LOAD MODEL (once at startup) ────────────────────────────────────────────
25
  print("Loading model...")
26
  feature_extractor = ASTFeatureExtractor.from_pretrained(HF_REPO)
27
  model = ASTForAudioClassification.from_pretrained(HF_REPO)
@@ -30,7 +30,7 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
30
  model.to(DEVICE)
31
  print(f"Model ready on {DEVICE}!")
32
 
33
- # ── AUDIO HELPERS ───────────────────────────────────────────────────────────
34
  def load_audio(path):
35
  y, _ = librosa.load(path, sr=SAMPLE_RATE, mono=True)
36
  return y.astype(np.float32)
@@ -50,7 +50,7 @@ def center_crop(y):
50
  return y[start:start + MAX_LENGTH]
51
  return np.pad(y, (0, MAX_LENGTH - len(y)))
52
 
53
- # ── PREDICTION WITH TTA ─────────────────────────────────────────────────────
54
  def predict(audio_path):
55
  if audio_path is None:
56
  return "Please upload an audio file.", None
@@ -91,7 +91,7 @@ def predict(audio_path):
91
  result = f"## {GENRE_EMOJI.get(pred_genre, '')} {pred_genre.capitalize()}\n**Confidence: {confidence:.1f}%**"
92
  return result, label_probs
93
 
94
- # ── GRADIO UI ────────────────────────────────────────────────────────────────
95
  with gr.Blocks(title="🎡 Music Genre Classifier") as demo:
96
  gr.Markdown(
97
  """
@@ -129,4 +129,4 @@ with gr.Blocks(title="🎡 Music Genre Classifier") as demo:
129
  )
130
 
131
  if __name__ == "__main__":
132
- demo.launch()
 
4
  import numpy as np
5
  from transformers import ASTFeatureExtractor, ASTForAudioClassification
6
 
7
+ # CONFIG───────
8
+ HF_REPO = "vectorverse/Messy_Mashup_Genre_Classifier"
9
  SAMPLE_RATE = 16000
10
  DURATION = 20
11
  MAX_LENGTH = SAMPLE_RATE * DURATION
 
21
  "reggae": "🌴", "rock": "πŸ”₯"
22
  }
23
 
24
+ #LOAD MODEL (once at startup)
25
  print("Loading model...")
26
  feature_extractor = ASTFeatureExtractor.from_pretrained(HF_REPO)
27
  model = ASTForAudioClassification.from_pretrained(HF_REPO)
 
30
  model.to(DEVICE)
31
  print(f"Model ready on {DEVICE}!")
32
 
33
+ # AUDIO HELPERS
34
  def load_audio(path):
35
  y, _ = librosa.load(path, sr=SAMPLE_RATE, mono=True)
36
  return y.astype(np.float32)
 
50
  return y[start:start + MAX_LENGTH]
51
  return np.pad(y, (0, MAX_LENGTH - len(y)))
52
 
53
+ # PREDICTION WITH TTA
54
  def predict(audio_path):
55
  if audio_path is None:
56
  return "Please upload an audio file.", None
 
91
  result = f"## {GENRE_EMOJI.get(pred_genre, '')} {pred_genre.capitalize()}\n**Confidence: {confidence:.1f}%**"
92
  return result, label_probs
93
 
94
+ # GRADIO UI
95
  with gr.Blocks(title="🎡 Music Genre Classifier") as demo:
96
  gr.Markdown(
97
  """
 
129
  )
130
 
131
  if __name__ == "__main__":
132
+ demo.launch()