Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
e1ef382
1
Parent(s):
76339ca
Add Prompts
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from audio_index import AudioEmbeddingSystem
|
4 |
-
from search import search
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
|
@@ -19,7 +19,10 @@ index_file = hf_hub_download(
|
|
19 |
audio_embedding_system = AudioEmbeddingSystem(db_path=db_file, index_path=index_file)
|
20 |
|
21 |
|
22 |
-
def audio_search(audio_tuple):
|
|
|
|
|
|
|
23 |
sample_rate, array = audio_tuple
|
24 |
if array.dtype == np.int16:
|
25 |
array = array.astype(np.float32) / 32768.0
|
@@ -41,13 +44,18 @@ def audio_search(audio_tuple):
|
|
41 |
by="distance", ascending=True
|
42 |
)
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
iface = gr.Interface(
|
46 |
fn=audio_search,
|
47 |
-
inputs=gr.Audio(
|
48 |
label="Record or upload a clip of your voice", sources=["microphone", "upload"]
|
49 |
-
),
|
50 |
outputs=gr.Dataframe(
|
|
|
51 |
headers=["path", "audio", "sentence", "distance"],
|
52 |
datatype=["str", "html", "str", "number"],
|
53 |
),
|
@@ -56,7 +64,7 @@ with gr.Blocks() as demo:
|
|
56 |
gr.HTML(
|
57 |
f"""
|
58 |
<h1 style='text-align: center; display: flex; align-items: center; justify-content: center;'>
|
59 |
-
<img src="/gradio_api/file=Karaoke_Huggy.png" alt="Voice Match" style="
|
60 |
</h1>
|
61 |
"""
|
62 |
)
|
@@ -75,5 +83,6 @@ with gr.Blocks() as demo:
|
|
75 |
"""
|
76 |
)
|
77 |
iface.render()
|
|
|
78 |
|
79 |
demo.launch(allowed_paths=["Karaoke_Huggy.png"])
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import hf_hub_download
|
3 |
from audio_index import AudioEmbeddingSystem
|
4 |
+
from search import search, get_prompt
|
5 |
import pandas as pd
|
6 |
import numpy as np
|
7 |
|
|
|
19 |
audio_embedding_system = AudioEmbeddingSystem(db_path=db_file, index_path=index_file)
|
20 |
|
21 |
|
22 |
+
def audio_search(audio_tuple, prompt: str):
|
23 |
+
if audio_tuple is None:
|
24 |
+
return gr.skip()
|
25 |
+
|
26 |
sample_rate, array = audio_tuple
|
27 |
if array.dtype == np.int16:
|
28 |
array = array.astype(np.float32) / 32768.0
|
|
|
44 |
by="distance", ascending=True
|
45 |
)
|
46 |
|
47 |
+
sample_text = gr.Textbox(
|
48 |
+
label="Prompt",
|
49 |
+
info="Hit Enter to get a prompt from the common voice dataset",
|
50 |
+
value=get_prompt(),
|
51 |
+
)
|
52 |
iface = gr.Interface(
|
53 |
fn=audio_search,
|
54 |
+
inputs=[gr.Audio(
|
55 |
label="Record or upload a clip of your voice", sources=["microphone", "upload"]
|
56 |
+
), sample_text],
|
57 |
outputs=gr.Dataframe(
|
58 |
+
show_label=False,
|
59 |
headers=["path", "audio", "sentence", "distance"],
|
60 |
datatype=["str", "html", "str", "number"],
|
61 |
),
|
|
|
64 |
gr.HTML(
|
65 |
f"""
|
66 |
<h1 style='text-align: center; display: flex; align-items: center; justify-content: center;'>
|
67 |
+
<img src="/gradio_api/file=Karaoke_Huggy.png" alt="Voice Match" style="height: 100px; margin-right: 10px"> Voice Match
|
68 |
</h1>
|
69 |
"""
|
70 |
)
|
|
|
83 |
"""
|
84 |
)
|
85 |
iface.render()
|
86 |
+
sample_text.submit(fn=get_prompt, inputs=None, outputs=sample_text)
|
87 |
|
88 |
demo.launch(allowed_paths=["Karaoke_Huggy.png"])
|
search.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import requests
|
2 |
import os
|
3 |
-
|
4 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
5 |
|
6 |
dataset = "mozilla-foundation/common_voice_17_0"
|
@@ -27,6 +27,16 @@ def _search(paths: list[str]):
|
|
27 |
return data.get("rows", [])
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def search(rows: list[dict]):
|
31 |
file_paths_to_find = [row["path"] for row in rows]
|
32 |
train_paths = []
|
@@ -41,14 +51,3 @@ def search(rows: list[dict]):
|
|
41 |
validation_rows = _search(validation_paths)
|
42 |
|
43 |
return train_rows + validation_rows
|
44 |
-
|
45 |
-
paths_in_clause = ", ".join([f"'{path}'" for path in file_paths_to_find])
|
46 |
-
where_clause = f'"path" IN ({paths_in_clause})'
|
47 |
-
|
48 |
-
api_url = f"https://datasets-server.huggingface.co/filter?dataset={dataset}&config={config}&split={split}&where={where_clause}&offset=0"
|
49 |
-
|
50 |
-
response = requests.get(api_url, headers=headers)
|
51 |
-
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
|
52 |
-
data = response.json()
|
53 |
-
|
54 |
-
return data.get("rows", [])
|
|
|
1 |
import requests
|
2 |
import os
|
3 |
+
import random
|
4 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
5 |
|
6 |
dataset = "mozilla-foundation/common_voice_17_0"
|
|
|
27 |
return data.get("rows", [])
|
28 |
|
29 |
|
30 |
+
def get_prompt():
|
31 |
+
"""Get a random sentence from the Common Voice dataset"""
|
32 |
+
offset = random.randint(0, 100_000)
|
33 |
+
api_url = f"https://datasets-server.huggingface.co/rows?dataset={dataset}&config={config}&split=train&offset={offset}&length=1"
|
34 |
+
response = requests.get(api_url, headers=headers)
|
35 |
+
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
|
36 |
+
data = response.json()
|
37 |
+
return data.get("rows", [])[0]["row"]["sentence"]
|
38 |
+
|
39 |
+
|
40 |
def search(rows: list[dict]):
|
41 |
file_paths_to_find = [row["path"] for row in rows]
|
42 |
train_paths = []
|
|
|
51 |
validation_rows = _search(validation_paths)
|
52 |
|
53 |
return train_rows + validation_rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|