Marcos12886 commited on
Commit
5cf41d0
1 Parent(s): a921dc5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+ from model import SAMPLING_RATE, clasificador, monitor
5
+ # modelo = monitor
6
+ modelo = clasificador
7
+ pipe = pipeline("audio-classification", model=f"A-POR-LOS-8000/distilhubert-finetuned-cry-detector", device="cuda")
8
+
9
+ def transcribe(audio):
10
+ _, y = audio
11
+ y = y.astype(np.float32) # con torch.float32 da error
12
+ y /= np.max(np.abs(y))
13
+ results = pipe({"sampling_rate": SAMPLING_RATE, "raw": y})
14
+ top_result = results[0] # Get the top result (most likely classification)
15
+ label = top_result["label"] # Extract the label from the top result
16
+ return label
17
+
18
+ demo = gr.Interface(
19
+ transcribe,
20
+ gr.Audio(
21
+ min_length=1.0,
22
+ max_length=10.0,
23
+ format="wav",
24
+ ),
25
+ "text",
26
+ )
27
+ demo.launch()