Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,12 +36,24 @@ def compare_text_to_audio_embeddings(text, pickle_file):
|
|
| 36 |
|
| 37 |
def get_matches(text_query):
|
| 38 |
matches = compare_text_to_audio_embeddings(text_query, "audio_embeddings_v3.pkl")
|
| 39 |
-
|
| 40 |
# Format the output
|
| 41 |
-
output = f"Top 5 matches for '{text_query}'
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return output
|
| 46 |
|
| 47 |
# Create the Gradio interface
|
|
|
|
| 36 |
|
| 37 |
def get_matches(text_query):
|
| 38 |
matches = compare_text_to_audio_embeddings(text_query, "audio_embeddings_v3.pkl")
|
| 39 |
+
|
| 40 |
# Format the output
|
| 41 |
+
output = f"## Top 5 matches for '{text_query}'\n\n"
|
| 42 |
+
|
| 43 |
+
for filename, url, similarity in matches[:3]:
|
| 44 |
+
output += f"{similarity:.4f}\n"
|
| 45 |
+
|
| 46 |
+
# Check if the URL is a YouTube URL
|
| 47 |
+
if "youtube.com" in url or "youtu.be" in url:
|
| 48 |
+
# Extract video ID from the URL
|
| 49 |
+
video_id = url.split("v=")[-1] if "v=" in url else url.split("/")[-1]
|
| 50 |
+
|
| 51 |
+
# Create iframe for YouTube video
|
| 52 |
+
output += f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>\n\n'
|
| 53 |
+
else:
|
| 54 |
+
# Use regular link for non-YouTube URLs
|
| 55 |
+
output += f'<a href="{url}">{url}</a>\n\n'
|
| 56 |
+
|
| 57 |
return output
|
| 58 |
|
| 59 |
# Create the Gradio interface
|