Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +66 -0
- training_embeddings.csv +0 -0
- training_embeddings.npy +3 -0
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from similarity import CLAPSimilarity
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
|
| 5 |
+
# Initialize the CLAPSimilarity instance
|
| 6 |
+
similarity_calculator = CLAPSimilarity(training_embeddings_prefix='training')
|
| 7 |
+
|
| 8 |
+
def process_query(text, audio_file, max_tracks):
|
| 9 |
+
if text and not audio_file:
|
| 10 |
+
# Process text input
|
| 11 |
+
similarity_scores = similarity_calculator.compute_similarity(
|
| 12 |
+
input_data=text,
|
| 13 |
+
input_type='text',
|
| 14 |
+
max_tracks=int(max_tracks) # Use user-defined max_tracks
|
| 15 |
+
)
|
| 16 |
+
elif audio_file and not text:
|
| 17 |
+
# Process audio input
|
| 18 |
+
similarity_scores = similarity_calculator.compute_similarity(
|
| 19 |
+
input_data=audio_file,
|
| 20 |
+
input_type='audio',
|
| 21 |
+
max_tracks=int(max_tracks) # Use user-defined max_tracks
|
| 22 |
+
)
|
| 23 |
+
else:
|
| 24 |
+
return "Please provide either text or audio input."
|
| 25 |
+
|
| 26 |
+
# Calculate the total sum of scores
|
| 27 |
+
total_score = sum(similarity_scores.values())
|
| 28 |
+
|
| 29 |
+
# Normalize the scores to sum to 100%
|
| 30 |
+
normalized_scores = {
|
| 31 |
+
filename: (score / total_score) * 100
|
| 32 |
+
for filename, score in similarity_scores.items()
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# Prepare the output data with normalized scores
|
| 36 |
+
data = [
|
| 37 |
+
[filename, round(score, 2)]
|
| 38 |
+
for filename, score in normalized_scores.items()
|
| 39 |
+
]
|
| 40 |
+
return data
|
| 41 |
+
|
| 42 |
+
with gr.Blocks() as demo:
|
| 43 |
+
with gr.Row():
|
| 44 |
+
text_input = gr.Textbox(label="Enter text query")
|
| 45 |
+
audio_input = gr.Audio(label="Upload audio", type="filepath")
|
| 46 |
+
max_tracks_input = gr.Number(
|
| 47 |
+
label="Max Tracks", value=10, precision=0
|
| 48 |
+
) # Add this input field
|
| 49 |
+
|
| 50 |
+
with gr.Row():
|
| 51 |
+
submit_btn = gr.Button("Submit")
|
| 52 |
+
|
| 53 |
+
output_table = gr.Dataframe(
|
| 54 |
+
headers=["Filename", "Score"],
|
| 55 |
+
label="Similarity Results",
|
| 56 |
+
datatype=["str", "number"],
|
| 57 |
+
interactive=False
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
submit_btn.click(
|
| 61 |
+
fn=process_query,
|
| 62 |
+
inputs=[text_input, audio_input, max_tracks_input], # Include max_tracks_input
|
| 63 |
+
outputs=[output_table]
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
demo.launch()
|
training_embeddings.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
training_embeddings.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fb0ef953a91710e1193e89a7ffa258e5d9f96e236997914823f58681586c9ea7
|
| 3 |
+
size 20608
|