File size: 798 Bytes
5cf41d0
 
 
8798354
36a48ee
8798354
 
 
5cf41d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8798354
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
29
30
import gradio as gr
from transformers import pipeline
import numpy as np
from model import SAMPLING_RATE
os.getenv('MODEL_REPO_ID')
modelo = "mixed-data"
# modelo = "cry-detector"
pipe = pipeline("audio-classification", model=f"A-POR-LOS-8000/distilhubert-finetuned-{modelo}")

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()