Martí Umbert
commited on
Commit
·
fab9582
1
Parent(s):
6c99403
app files
Browse files- app.py +12 -0
- app_dcase.py +75 -0
app.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import app_dcase
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
|
| 6 |
+
demo = gr.TabbedInterface([app_dcase.create_app()],
|
| 7 |
+
["DCASE demo"])
|
| 8 |
+
|
| 9 |
+
demo.launch()
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
main()
|
app_dcase.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
import gradio as gr
|
| 26 |
+
from dcase24t6.nn.hub import baseline_pipeline
|
| 27 |
+
|
| 28 |
+
model = baseline_pipeline()
|
| 29 |
+
|
| 30 |
+
def dcase_inference(mic=None, file=None):
|
| 31 |
+
|
| 32 |
+
if mic is not None:
|
| 33 |
+
audio, sr = mic
|
| 34 |
+
print(f"sr 1: {sr}")
|
| 35 |
+
elif file is not None:
|
| 36 |
+
audio, sr = file
|
| 37 |
+
print(f"file 1: {sr}")
|
| 38 |
+
else:
|
| 39 |
+
return "You must either provide a mic recording or a file"
|
| 40 |
+
|
| 41 |
+
# Generate captions for the recording
|
| 42 |
+
item = {"audio": audio, "sr": sr}
|
| 43 |
+
outputs = model(item)
|
| 44 |
+
candidate = outputs["candidates"][0]
|
| 45 |
+
|
| 46 |
+
return candidate
|
| 47 |
+
|
| 48 |
+
def create_app():
|
| 49 |
+
|
| 50 |
+
with gr.Blocks() as demo:
|
| 51 |
+
gr.Markdown(
|
| 52 |
+
"""
|
| 53 |
+
# DCASE demo for automatic audio captioning
|
| 54 |
+
"""
|
| 55 |
+
)
|
| 56 |
+
gr.Interface(
|
| 57 |
+
fn=dcase_inference,
|
| 58 |
+
inputs=[
|
| 59 |
+
gr.Audio(sources="microphone", type="filepath"),
|
| 60 |
+
gr.Audio(sources="upload", type="filepath"),
|
| 61 |
+
],
|
| 62 |
+
outputs="text",
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
return demo
|
| 66 |
+
|
| 67 |
+
def main():
|
| 68 |
+
|
| 69 |
+
app = create_app()
|
| 70 |
+
app.launch(debug=True)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
main()
|
| 75 |
+
|