msis commited on
Commit
24dd290
1 Parent(s): 805f7ee

adds model selection from wandb

Browse files
Files changed (2) hide show
  1. CnLgGm025_SpeUni1024_DI_EATL.nemo +0 -3
  2. app.py +55 -6
CnLgGm025_SpeUni1024_DI_EATL.nemo DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:94d7a7443c60dddb1e7ddfdcf5f2e85a2a857b2bc31bf20b4aedf8979b866183
3
- size 566712320
 
 
 
 
app.py CHANGED
@@ -1,16 +1,51 @@
 
1
  import gradio as gr
 
2
  import nemo.collections.asr as nemo_asr
3
 
4
- model = nemo_asr.models.ASRModel.restore_from("CnLgGm025_SpeUni1024_DI_EATL.nemo")
5
- model.eval()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  def transcribe(audio_mic, audio_file, models_names):
 
9
  # transcribe audio_mic and audio_file separately
10
  # because transcribe() fails is path is empty
11
  transcription_mic = "\n".join(
12
  [
13
- f"{model_name} => {model.transcribe([audio_mic])[0]}"
14
  for model_name in models_names
15
  ]
16
  if audio_mic
@@ -18,7 +53,7 @@ def transcribe(audio_mic, audio_file, models_names):
18
  )
19
  transcription_file = "\n".join(
20
  [
21
- f"{model_name} => {model.transcribe([audio_file])[0]}"
22
  for model_name in models_names
23
  ]
24
  if audio_file
@@ -27,12 +62,24 @@ def transcribe(audio_mic, audio_file, models_names):
27
  return transcription_mic, transcription_file
28
 
29
 
30
- selection = ["a", "b", "c"]
31
 
32
  demo = gr.Blocks()
33
 
34
  with demo:
35
- models_names = gr.CheckboxGroup(selection)
 
 
 
 
 
 
 
 
 
 
 
 
36
  with gr.Row():
37
  audio_mic = gr.Audio(source="microphone", type="filepath", label="Microphone")
38
  audio_file = gr.Audio(source="upload", type="filepath", label="File")
@@ -41,6 +88,8 @@ with demo:
41
  output_mic = gr.TextArea(label="Microphone Transcription")
42
  output_file = gr.TextArea(label="Audio Transcription")
43
 
 
 
44
  b1 = gr.Button("Transcribe")
45
 
46
  b1.click(
 
1
+ import wandb
2
  import gradio as gr
3
+ from datetime import datetime, timedelta
4
  import nemo.collections.asr as nemo_asr
5
 
6
+ wandb_api = wandb.Api()
7
+
8
+ all_artifacts_versions = [
9
+ version
10
+ for version in [
11
+ collection.versions()
12
+ for collection in wandb_api.artifact_type(
13
+ type_name="model", project="nemo-experiments"
14
+ ).collections()
15
+ ]
16
+ ]
17
+
18
+ latest_artifacts = [
19
+ artifact
20
+ for artifact_versions in all_artifacts_versions
21
+ for artifact in artifact_versions
22
+ if (
23
+ datetime.fromisoformat(artifact.created_at)
24
+ > datetime.now() - timedelta(days=180) # last 180 days
25
+ and artifact.state != "DELETED"
26
+ )
27
+ ]
28
+
29
+ models = {artifact.name: None for artifact in latest_artifacts}
30
+
31
+
32
+ def lazy_load_models(models_names):
33
+ for model_name in models_names:
34
+ model = models[model_name]
35
+ if not model:
36
+ models[model_name] = nemo_asr.models.ASRModel.restore_from(
37
+ list(filter(lambda x: x.name == model_name, latest_artifacts))[0].file()
38
+ )
39
+ models[model_name].eval()
40
 
41
 
42
  def transcribe(audio_mic, audio_file, models_names):
43
+ lazy_load_models(models_names)
44
  # transcribe audio_mic and audio_file separately
45
  # because transcribe() fails is path is empty
46
  transcription_mic = "\n".join(
47
  [
48
+ f"{model_name} => {models[model_name].transcribe([audio_mic])[0]}"
49
  for model_name in models_names
50
  ]
51
  if audio_mic
 
53
  )
54
  transcription_file = "\n".join(
55
  [
56
+ f"{model_name} => {models[model_name].transcribe([audio_file])[0]}"
57
  for model_name in models_names
58
  ]
59
  if audio_file
 
62
  return transcription_mic, transcription_file
63
 
64
 
65
+ model_selection = list(models.keys())
66
 
67
  demo = gr.Blocks()
68
 
69
  with demo:
70
+ gr.Markdown(
71
+ """
72
+ # ﷽
73
+ These are the latest* Tarteel models.
74
+
75
+ Please note that the models are lazy loaded.
76
+ This means that the first time you use a model,
77
+ it might take some time to be downloaded and loaded for inference.
78
+
79
+ *: last 180 days since the space was launched.
80
+ To update the list, restart the space.
81
+ """
82
+ )
83
  with gr.Row():
84
  audio_mic = gr.Audio(source="microphone", type="filepath", label="Microphone")
85
  audio_file = gr.Audio(source="upload", type="filepath", label="File")
 
88
  output_mic = gr.TextArea(label="Microphone Transcription")
89
  output_file = gr.TextArea(label="Audio Transcription")
90
 
91
+ models_names = gr.CheckboxGroup(model_selection, label="Select Models to Use")
92
+
93
  b1 = gr.Button("Transcribe")
94
 
95
  b1.click(