Upload folder using huggingface_hub
Browse files- .gitattributes +3 -9
- .github/workflows/update_space.yml +28 -0
- README.md +3 -8
- app.py +108 -0
- requirements.txt +2 -0
- samples/cate_blanch.mp3 +0 -0
- samples/cate_blanch_2.mp3 +0 -0
- samples/cate_blanch_3.mp3 +0 -0
- samples/denzel_washington.mp3 +0 -0
- samples/heath_ledger.mp3 +0 -0
- samples/heath_ledger_2.mp3 +0 -0
- samples/heath_ledger_3.mp3 +0 -0
- samples/kirsten_dunst.wav +3 -0
- samples/leonardo_dicaprio.mp3 +0 -0
- samples/naomi_watts.mp3 +0 -0
- samples/russel_crowe.mp3 +0 -0
- samples/russel_crowe_2.mp3 +0 -0
.gitattributes
CHANGED
@@ -1,34 +1,28 @@
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
11 |
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
13 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
17 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
20 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
|
|
24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
samples/kirsten_dunst.wav filter=lfs diff=lfs merge=lfs -text
|
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install https://gradio-builds.s3.amazonaws.com/c0138fa3cf227b01cdc468c7817298d5f7849c9e/gradio-3.32.0-py3-none-any.whl
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
README.md
CHANGED
@@ -1,12 +1,7 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.32.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: same-test
|
3 |
+
app_file: app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 3.32.0
|
|
|
|
|
6 |
---
|
7 |
+
test readme
|
|
app.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from torchaudio.sox_effects import apply_effects_file
|
4 |
+
from transformers import AutoFeatureExtractor, AutoModelForAudioXVector
|
5 |
+
|
6 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
|
8 |
+
OUTPUT_OK = (
|
9 |
+
"""
|
10 |
+
<div class="container">
|
11 |
+
<div class="row"><h1 style="text-align: center">The speakers are</h1></div>
|
12 |
+
<div class="row"><h1 class="display-1 text-success" style="text-align: center">{:.1f}%</h1></div>
|
13 |
+
<div class="row"><h1 style="text-align: center">similar</h1></div>
|
14 |
+
<div class="row"><h1 class="text-success" style="text-align: center">Welcome, human!</h1></div>
|
15 |
+
<div class="row"><small style="text-align: center">(You must get at least 85% to be considered the same person)</small><div class="row">
|
16 |
+
</div>
|
17 |
+
"""
|
18 |
+
)
|
19 |
+
OUTPUT_FAIL = (
|
20 |
+
"""
|
21 |
+
<div class="container">
|
22 |
+
<div class="row"><h1 style="text-align: center">The speakers are</h1></div>
|
23 |
+
<div class="row"><h1 class="display-1 text-danger" style="text-align: center">{:.1f}%</h1></div>
|
24 |
+
<div class="row"><h1 style="text-align: center">similar</h1></div>
|
25 |
+
<div class="row"><h1 class="text-danger" style="text-align: center">You shall not pass!</h1></div>
|
26 |
+
<div class="row"><small style="text-align: center">(You must get at least 85% to be considered the same person)</small><div class="row">
|
27 |
+
</div>
|
28 |
+
"""
|
29 |
+
)
|
30 |
+
|
31 |
+
EFFECTS = [
|
32 |
+
["remix", "-"],
|
33 |
+
["channels", "1"],
|
34 |
+
["rate", "16000"],
|
35 |
+
["gain", "-1.0"],
|
36 |
+
["silence", "1", "0.1", "0.1%", "-1", "0.1", "0.1%"],
|
37 |
+
["trim", "0", "10"],
|
38 |
+
]
|
39 |
+
|
40 |
+
THRESHOLD = 0.85
|
41 |
+
|
42 |
+
model_name = "microsoft/unispeech-sat-base-plus-sv"
|
43 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
44 |
+
model = AutoModelForAudioXVector.from_pretrained(model_name).to(device)
|
45 |
+
cosine_sim = torch.nn.CosineSimilarity(dim=-1)
|
46 |
+
|
47 |
+
|
48 |
+
def similarity_fn(path1, path2):
|
49 |
+
if not (path1 and path2):
|
50 |
+
return '<b style="color:red">ERROR: Please record audio for *both* speakers!</b>'
|
51 |
+
|
52 |
+
wav1, _ = apply_effects_file(path1, EFFECTS)
|
53 |
+
wav2, _ = apply_effects_file(path2, EFFECTS)
|
54 |
+
print(wav1.shape, wav2.shape)
|
55 |
+
|
56 |
+
input1 = feature_extractor(wav1.squeeze(0), return_tensors="pt", sampling_rate=16000).input_values.to(device)
|
57 |
+
input2 = feature_extractor(wav2.squeeze(0), return_tensors="pt", sampling_rate=16000).input_values.to(device)
|
58 |
+
|
59 |
+
with torch.no_grad():
|
60 |
+
emb1 = model(input1).embeddings
|
61 |
+
emb2 = model(input2).embeddings
|
62 |
+
emb1 = torch.nn.functional.normalize(emb1, dim=-1).cpu()
|
63 |
+
emb2 = torch.nn.functional.normalize(emb2, dim=-1).cpu()
|
64 |
+
similarity = cosine_sim(emb1, emb2).numpy()[0]
|
65 |
+
|
66 |
+
if similarity >= THRESHOLD:
|
67 |
+
output = OUTPUT_OK.format(similarity * 100)
|
68 |
+
else:
|
69 |
+
output = OUTPUT_FAIL.format(similarity * 100)
|
70 |
+
|
71 |
+
return output
|
72 |
+
|
73 |
+
|
74 |
+
inputs = [
|
75 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Speaker #1"),
|
76 |
+
gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Speaker #2"),
|
77 |
+
]
|
78 |
+
output = gr.outputs.HTML(label="")
|
79 |
+
|
80 |
+
|
81 |
+
description = (
|
82 |
+
"This demo from Microsoft will compare two speech samples and determine if they are from the same speaker. "
|
83 |
+
"Try it with your own voice!"
|
84 |
+
)
|
85 |
+
article = (
|
86 |
+
"<p style='text-align: center'>"
|
87 |
+
"<a href='https://huggingface.co/microsoft/unispeech-sat-large-sv' target='_blank'>ποΈ Learn more about UniSpeech-SAT</a> | "
|
88 |
+
"<a href='https://arxiv.org/abs/2110.05752' target='_blank'>π UniSpeech-SAT paper</a> | "
|
89 |
+
"<a href='https://www.danielpovey.com/files/2018_icassp_xvectors.pdf' target='_blank'>π X-Vector paper</a>"
|
90 |
+
"</p>"
|
91 |
+
)
|
92 |
+
examples = [
|
93 |
+
["samples/cate_blanch.mp3", "samples/cate_blanch_2.mp3"],
|
94 |
+
["samples/cate_blanch.mp3", "samples/kirsten_dunst.wav"],
|
95 |
+
]
|
96 |
+
|
97 |
+
interface = gr.Interface(
|
98 |
+
fn=similarity_fn,
|
99 |
+
inputs=inputs,
|
100 |
+
outputs=output,
|
101 |
+
description=description,
|
102 |
+
layout="horizontal",
|
103 |
+
theme="huggingface",
|
104 |
+
allow_flagging=False,
|
105 |
+
live=False,
|
106 |
+
examples=examples,
|
107 |
+
)
|
108 |
+
interface.launch(enable_queue=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers
|
2 |
+
torchaudio
|
samples/cate_blanch.mp3
ADDED
Binary file (67.2 kB). View file
|
|
samples/cate_blanch_2.mp3
ADDED
Binary file (35.8 kB). View file
|
|
samples/cate_blanch_3.mp3
ADDED
Binary file (43.6 kB). View file
|
|
samples/denzel_washington.mp3
ADDED
Binary file (26.6 kB). View file
|
|
samples/heath_ledger.mp3
ADDED
Binary file (28.4 kB). View file
|
|
samples/heath_ledger_2.mp3
ADDED
Binary file (18 kB). View file
|
|
samples/heath_ledger_3.mp3
ADDED
Binary file (55.8 kB). View file
|
|
samples/kirsten_dunst.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7ab77b27959f0f43126c94c4de3baa23b3f92c3c2e26ba322af2d6cd688f3233
|
3 |
+
size 1287798
|
samples/leonardo_dicaprio.mp3
ADDED
Binary file (71.8 kB). View file
|
|
samples/naomi_watts.mp3
ADDED
Binary file (35.3 kB). View file
|
|
samples/russel_crowe.mp3
ADDED
Binary file (52.2 kB). View file
|
|
samples/russel_crowe_2.mp3
ADDED
Binary file (66.6 kB). View file
|
|