marshal-yash commited on
Commit
96d5fd4
·
verified ·
1 Parent(s): 7ff2be2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import librosa
4
+ from transformers import AutoProcessor, ClapModel
5
+
6
+ # Load model globally for speed
7
+ model_id = "laion/clap-htsat-unfused"
8
+ processor = AutoProcessor.from_pretrained(model_id)
9
+ model = ClapModel.from_pretrained(model_id)
10
+
11
+ def get_vibe_vector(audio_path):
12
+ # Load and resample to 48kHz (required for CLAP)
13
+ y, sr = librosa.load(audio_path, sr=48000, duration=30)
14
+ inputs = processor(audios=y, return_tensors="pt", sampling_rate=48000)
15
+ with torch.no_grad():
16
+ embeddings = model.get_audio_features(**inputs)
17
+ return embeddings.numpy().flatten().tolist()
18
+
19
+ # Define the Gradio Interface
20
+ demo = gr.Interface(
21
+ fn=get_vibe_vector,
22
+ inputs=gr.Audio(type="filepath"),
23
+ outputs="json"
24
+ )
25
+ demo.launch()