Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,34 @@
|
|
| 1 |
import re
|
| 2 |
-
from gender_prediction import get_gender
|
| 3 |
-
import gradio as gr
|
| 4 |
import torch
|
|
|
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
interface
|
| 17 |
-
outputs=[gr.components.Textbox(label="your result")])
|
| 18 |
-
interface.launch(debug=True)
|
|
|
|
| 1 |
import re
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gender_prediction import get_gender
|
| 5 |
|
| 6 |
+
# Список аудиофайлов
|
| 7 |
+
audio_files = [
|
| 8 |
+
"https://huggingface.co/spaces/danielwm994/t1/resolve/main/1.mp3",
|
| 9 |
+
"https://huggingface.co/spaces/danielwm994/t1/resolve/main/2.mp3",
|
| 10 |
+
"https://huggingface.co/spaces/danielwm994/t1/resolve/main/3.mp3",
|
| 11 |
+
"https://huggingface.co/spaces/danielwm994/t1/resolve/main/4.mp3",
|
| 12 |
+
"https://huggingface.co/spaces/danielwm994/t1/resolve/main/5.mp3"
|
| 13 |
+
]
|
| 14 |
|
| 15 |
+
def process_audio():
|
| 16 |
+
model_name_or_path = "alefiury/wav2vec2-large-xlsr-53-gender-recognition-librispeech"
|
| 17 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 18 |
+
results = []
|
| 19 |
+
|
| 20 |
+
for voice in audio_files:
|
| 21 |
+
predicted_label = get_gender(model_name_or_path, [voice], device)
|
| 22 |
+
gender = re.search("female|male", predicted_label)
|
| 23 |
+
results.append({"url": voice, "gender": gender.group(0) if gender else "unknown"})
|
| 24 |
+
|
| 25 |
+
return results
|
| 26 |
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=process_audio,
|
| 29 |
+
inputs=[],
|
| 30 |
+
outputs=gr.JSON(label="Results"),
|
| 31 |
+
live=False
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
interface.launch(debug=True)
|
|
|
|
|
|