Martí Umbert
commited on
Commit
·
e117668
1
Parent(s):
973c908
app_dcase.py: include code from actual dcase demo
Browse files- app_dcase.py +33 -18
app_dcase.py
CHANGED
|
@@ -1,27 +1,40 @@
|
|
| 1 |
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from msclap import CLAP
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
captions = clap_model.generate_caption([audio],
|
| 18 |
-
resample=True,
|
| 19 |
-
beam_size=5,
|
| 20 |
-
entry_length=67,
|
| 21 |
-
temperature=0.01)
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def create_app():
|
| 27 |
|
|
@@ -32,7 +45,7 @@ def create_app():
|
|
| 32 |
"""
|
| 33 |
)
|
| 34 |
gr.Interface(
|
| 35 |
-
fn=
|
| 36 |
inputs=[
|
| 37 |
gr.Audio(sources="microphone", type="filepath"),
|
| 38 |
gr.Audio(sources="upload", type="filepath"),
|
|
@@ -42,6 +55,8 @@ def create_app():
|
|
| 42 |
|
| 43 |
return demo
|
| 44 |
|
|
|
|
|
|
|
| 45 |
def main():
|
| 46 |
|
| 47 |
app = create_app()
|
|
|
|
| 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 |
+
from transformers import pipeline
|
| 26 |
+
import gradio as gr
|
| 27 |
+
import torchaudio
|
| 28 |
+
import torch
|
| 29 |
+
from dcase24t6.nn.hub import baseline_pipeline
|
| 30 |
+
import os
|
| 31 |
+
import gdown
|
| 32 |
|
| 33 |
+
def download_dcase_model_checkpoint():
|
| 34 |
+
|
| 35 |
+
url = "https://drive.google.com/uc?id=1JABWIBlHuLAhYPX5ktbyLniH-YpeRyeT"
|
| 36 |
+
output = 'epoch_232-step_001864-mode_min-val_loss_3.3752.ckpt'
|
| 37 |
+
gdown.download(url, output, quiet=False)
|
| 38 |
|
| 39 |
def create_app():
|
| 40 |
|
|
|
|
| 45 |
"""
|
| 46 |
)
|
| 47 |
gr.Interface(
|
| 48 |
+
fn=dcase_inference,
|
| 49 |
inputs=[
|
| 50 |
gr.Audio(sources="microphone", type="filepath"),
|
| 51 |
gr.Audio(sources="upload", type="filepath"),
|
|
|
|
| 55 |
|
| 56 |
return demo
|
| 57 |
|
| 58 |
+
download_dcase_model_checkpoint()
|
| 59 |
+
|
| 60 |
def main():
|
| 61 |
|
| 62 |
app = create_app()
|