baguioni commited on
Commit
f150fa4
1 Parent(s): c5534e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -1,18 +1,38 @@
1
  import gradio as gr
 
2
 
3
  model = gr.Interface.load("huggingface/pyannote/voice-activity-detection")
4
 
 
 
 
 
 
 
 
 
 
5
  def inference(audio_file):
6
  output = model(audio_file)
7
- return output
 
8
 
9
  inputs = gr.inputs.Audio(label="Input Audio", type="filepath", source="microphone")
10
- outputs = gr.outputs.Label(type="auto", label = "Voice timestamps")
11
  title = "Voice Activity Detection"
12
- description = "Record or upload an audio file and detected human voices will be timestamped."
13
- article = "<a href = 'pyannote, https://github.com/pyannote/pyannote-audio"
 
 
 
 
 
 
 
 
 
 
14
 
15
- gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, theme="grass").launch(debug=True)
16
 
17
 
18
 
 
1
  import gradio as gr
2
+ import ast
3
 
4
  model = gr.Interface.load("huggingface/pyannote/voice-activity-detection")
5
 
6
+ def format_inference(output):
7
+ if output:
8
+ timestamps = []
9
+ for out in output:
10
+ timestamps.append(f"Start: {out['start']}s; Stop{out['stop']}s")
11
+ return "\n".join(timestamps)
12
+ else:
13
+ return "No voice activity detected."
14
+
15
  def inference(audio_file):
16
  output = model(audio_file)
17
+ output_list = ast.literal_eval(output)
18
+ return format_inference(output_list)
19
 
20
  inputs = gr.inputs.Audio(label="Input Audio", type="filepath", source="microphone")
21
+ outputs = gr.outputs.Textbox(label="Voice timestamps", type="auto")
22
  title = "Voice Activity Detection"
23
+ description = "Record or upload an audio file and detected voices will be timestamped."
24
+ examples = ['samples/talk.wav', 'samples/talk2.wav', 'samples/silence.wav', ]
25
+ article = "pyannote, https://github.com/pyannote/pyannote-audio"
26
+
27
+ gr.Interface(inference,
28
+ inputs,
29
+ outputs,
30
+ title=title,
31
+ description=description,
32
+ article=article,
33
+ examples=examples,
34
+ theme="grass").launch(debug=True)
35
 
 
36
 
37
 
38