Martí Umbert
commited on
Commit
·
9185348
1
Parent(s):
fb517ef
app_dcase.py: first commit of this file which now simulates calling DCASE baseline model
Browse files- app_dcase.py +53 -0
app_dcase.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from msclap import CLAP
|
4 |
+
|
5 |
+
clap_model = CLAP(version = 'clapcap', use_cuda=False)
|
6 |
+
|
7 |
+
def clap_inference(mic=None, file=None):
|
8 |
+
|
9 |
+
if mic is not None:
|
10 |
+
audio = mic
|
11 |
+
elif file is not None:
|
12 |
+
audio = file
|
13 |
+
else:
|
14 |
+
return "You must either provide a mic recording or a file"
|
15 |
+
|
16 |
+
# Generate captions for the recording
|
17 |
+
captions = clap_model.generate_caption([audio],
|
18 |
+
resample=True,
|
19 |
+
beam_size=5,
|
20 |
+
entry_length=67,
|
21 |
+
temperature=0.01)
|
22 |
+
|
23 |
+
return captions[0]
|
24 |
+
|
25 |
+
|
26 |
+
def create_app():
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown(
|
30 |
+
"""
|
31 |
+
# DCASE demo for automatic audio captioning
|
32 |
+
"""
|
33 |
+
)
|
34 |
+
gr.Interface(
|
35 |
+
fn=clap_inference,
|
36 |
+
inputs=[
|
37 |
+
gr.Audio(sources="microphone", type="filepath"),
|
38 |
+
gr.Audio(sources="upload", type="filepath"),
|
39 |
+
],
|
40 |
+
outputs="text",
|
41 |
+
)
|
42 |
+
|
43 |
+
return demo
|
44 |
+
|
45 |
+
def main():
|
46 |
+
|
47 |
+
app = create_app()
|
48 |
+
app.launch(debug=True)
|
49 |
+
|
50 |
+
|
51 |
+
if __name__ == "__main__":
|
52 |
+
main()
|
53 |
+
|