rmayormartins
commited on
Commit
•
0f1a690
1
Parent(s):
82203f6
Subindo arquivos33
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import torch
|
|
3 |
import numpy as np
|
4 |
from transformers import Wav2Vec2Processor, Wav2Vec2ForSequenceClassification
|
5 |
|
6 |
-
# modelo e o processador
|
7 |
model_name = "results"
|
8 |
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
9 |
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
|
@@ -15,12 +15,12 @@ def classify_accent(audio):
|
|
15 |
# entrada
|
16 |
print(f"Tipo de entrada de áudio: {type(audio)}")
|
17 |
|
18 |
-
#
|
19 |
print(f"Received audio input: {audio}")
|
20 |
|
21 |
try:
|
22 |
-
audio_array = audio[1] # O áudio da tupla
|
23 |
-
sample_rate = audio[0] # A taxa de amostragem da tupla
|
24 |
|
25 |
print(f"Shape do áudio: {audio_array.shape}, Taxa de amostragem: {sample_rate}")
|
26 |
|
@@ -38,20 +38,20 @@ def classify_accent(audio):
|
|
38 |
logits = model(input_values).logits
|
39 |
predicted_ids = torch.argmax(logits, dim=-1).item()
|
40 |
|
41 |
-
#
|
42 |
-
labels = ["Brazilian", "
|
43 |
return labels[predicted_ids]
|
44 |
|
45 |
except Exception as e:
|
46 |
return f"Erro ao processar o áudio: {str(e)}"
|
47 |
|
48 |
-
#
|
49 |
description_html = """
|
50 |
<p>Test with recording or uploading an audio file. To test, I recommend short sentences.</p>
|
51 |
<p>Ramon Mayor Martins: <a href="https://rmayormartins.github.io/" target="_blank">Website</a> | <a href="https://huggingface.co/rmayormartins" target="_blank">Spaces</a></p>
|
52 |
"""
|
53 |
|
54 |
-
#
|
55 |
interface = gr.Interface(
|
56 |
fn=classify_accent,
|
57 |
inputs=gr.Audio(type="numpy"),
|
|
|
3 |
import numpy as np
|
4 |
from transformers import Wav2Vec2Processor, Wav2Vec2ForSequenceClassification
|
5 |
|
6 |
+
# modelo e o processador
|
7 |
model_name = "results"
|
8 |
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
9 |
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name)
|
|
|
15 |
# entrada
|
16 |
print(f"Tipo de entrada de áudio: {type(audio)}")
|
17 |
|
18 |
+
# áudio
|
19 |
print(f"Received audio input: {audio}")
|
20 |
|
21 |
try:
|
22 |
+
audio_array = audio[1] # O áudio no segundo da tupla
|
23 |
+
sample_rate = audio[0] # A taxa de amostragem no primeiro da tupla
|
24 |
|
25 |
print(f"Shape do áudio: {audio_array.shape}, Taxa de amostragem: {sample_rate}")
|
26 |
|
|
|
38 |
logits = model(input_values).logits
|
39 |
predicted_ids = torch.argmax(logits, dim=-1).item()
|
40 |
|
41 |
+
# Mapeamento
|
42 |
+
labels = ["Brazilian", "Other"]
|
43 |
return labels[predicted_ids]
|
44 |
|
45 |
except Exception as e:
|
46 |
return f"Erro ao processar o áudio: {str(e)}"
|
47 |
|
48 |
+
#
|
49 |
description_html = """
|
50 |
<p>Test with recording or uploading an audio file. To test, I recommend short sentences.</p>
|
51 |
<p>Ramon Mayor Martins: <a href="https://rmayormartins.github.io/" target="_blank">Website</a> | <a href="https://huggingface.co/rmayormartins" target="_blank">Spaces</a></p>
|
52 |
"""
|
53 |
|
54 |
+
#
|
55 |
interface = gr.Interface(
|
56 |
fn=classify_accent,
|
57 |
inputs=gr.Audio(type="numpy"),
|