File size: 805 Bytes
5cf41d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from transformers import pipeline
import numpy as np
from model import SAMPLING_RATE, clasificador, monitor
# modelo = monitor
modelo = clasificador
pipe = pipeline("audio-classification", model=f"A-POR-LOS-8000/distilhubert-finetuned-cry-detector", device="cuda")

def transcribe(audio):
    _, y = audio
    y = y.astype(np.float32) # con torch.float32 da error
    y /= np.max(np.abs(y))
    results = pipe({"sampling_rate": SAMPLING_RATE, "raw": y})
    top_result = results[0]  # Get the top result (most likely classification)
    label = top_result["label"]  # Extract the label from the top result
    return label

demo = gr.Interface(
    transcribe,
    gr.Audio(
        min_length=1.0,
        max_length=10.0,
        format="wav",
        ),
    "text",
)
demo.launch()