rmayormartins
commited on
Commit
•
0a494dc
1
Parent(s):
2b0982f
Subindo arquivos131
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import numpy as np
|
4 |
-
from transformers import Wav2Vec2Processor
|
5 |
from safetensors.torch import load_file
|
6 |
|
7 |
# Carregar o modelo e o processador salvos
|
@@ -9,7 +9,8 @@ model_name = "results"
|
|
9 |
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
10 |
|
11 |
# Carregar o modelo do arquivo safetensors
|
12 |
-
|
|
|
13 |
|
14 |
def classify_accent(audio):
|
15 |
if audio is None:
|
@@ -22,8 +23,8 @@ def classify_accent(audio):
|
|
22 |
print(f"Entrada de audio recibida: {audio}")
|
23 |
|
24 |
try:
|
25 |
-
audio_array = audio[
|
26 |
-
sample_rate = audio[
|
27 |
|
28 |
print(f"Forma del audio: {audio_array.shape}, Frecuencia de muestreo: {sample_rate}")
|
29 |
|
@@ -58,7 +59,7 @@ description_html = """
|
|
58 |
# Interface do Gradio
|
59 |
interface = gr.Interface(
|
60 |
fn=classify_accent,
|
61 |
-
inputs=gr.Audio(type="numpy"),
|
62 |
outputs="label",
|
63 |
title="Clasificador de Sotaques (Español vs Otro)",
|
64 |
description=description_html
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import numpy as np
|
4 |
+
from transformers import Wav2Vec2Processor, Wav2Vec2ForSequenceClassification
|
5 |
from safetensors.torch import load_file
|
6 |
|
7 |
# Carregar o modelo e o processador salvos
|
|
|
9 |
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
10 |
|
11 |
# Carregar o modelo do arquivo safetensors
|
12 |
+
state_dict = load_file("results/model.safetensors")
|
13 |
+
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_name, state_dict=state_dict)
|
14 |
|
15 |
def classify_accent(audio):
|
16 |
if audio is None:
|
|
|
23 |
print(f"Entrada de audio recibida: {audio}")
|
24 |
|
25 |
try:
|
26 |
+
audio_array = audio["array"] # O áudio da tupla
|
27 |
+
sample_rate = audio["sampling_rate"] # A taxa de amostragem da tupla
|
28 |
|
29 |
print(f"Forma del audio: {audio_array.shape}, Frecuencia de muestreo: {sample_rate}")
|
30 |
|
|
|
59 |
# Interface do Gradio
|
60 |
interface = gr.Interface(
|
61 |
fn=classify_accent,
|
62 |
+
inputs=gr.Audio(type="numpy", source="microphone"),
|
63 |
outputs="label",
|
64 |
title="Clasificador de Sotaques (Español vs Otro)",
|
65 |
description=description_html
|