msis commited on
Commit
061f670
1 Parent(s): 7dc681a

simple app to transcribe

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. app.py +68 -0
  3. packages.txt +2 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ wandb/
2
+ artifacts/
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime, timedelta
2
+ import os
3
+
4
+ import gradio as gr
5
+ import torch
6
+ import nemo.collections.asr as nemo_asr
7
+ import wandb
8
+
9
+ MODEL_HISTORY_DAYS = 180
10
+ WANDB_ENTITY = os.environ.get("WANDB_ENTITY", "tarteel")
11
+ WANDB_PROJECT_NAME = os.environ.get("WANDB_PROJECT_NAME", "nemo-experiments")
12
+ MODEL_NAME = os.environ.get("MODEL_NAME", "CfCtcLg-SpeUni1024-DI-EATLDN-CA:v0")
13
+
14
+
15
+ def get_device():
16
+ if torch.cuda.is_available():
17
+ return "cuda"
18
+ else:
19
+ return "cpu"
20
+
21
+
22
+ # run = wandb.init(entity=WANDB_ENTITY, project=WANDB_PROJECT_NAME)
23
+ wandb_api = wandb.Api(overrides={"entity": WANDB_ENTITY})
24
+
25
+ artifact = wandb_api.artifact(f"{WANDB_ENTITY}/{WANDB_PROJECT_NAME}/{MODEL_NAME}")
26
+ artifact_dir = artifact.download()
27
+
28
+ # find the model (ending with .nemo) in the artifact directory
29
+ model_path = [
30
+ os.path.join(root, file)
31
+ for root, dirs, files in os.walk(artifact_dir)
32
+ for file in files
33
+ if file.endswith(".nemo")
34
+ ][0]
35
+
36
+ model = nemo_asr.models.EncDecCTCModelBPE.restore_from(
37
+ model_path, map_location=get_device()
38
+ )
39
+
40
+
41
+ def transcribe(audio_file):
42
+ transcription_file = model.transcribe([audio_file])[0]
43
+ return transcription_file
44
+
45
+
46
+ demo = gr.Blocks()
47
+
48
+ with demo:
49
+ gr.Markdown(
50
+ """
51
+ # ﷽
52
+ """
53
+ )
54
+ with gr.Row():
55
+ audio_file = gr.Audio(source="upload", type="filepath", label="File")
56
+
57
+ with gr.Row():
58
+ output_file = gr.TextArea(label="Audio Transcription")
59
+
60
+ b1 = gr.Button("Transcribe")
61
+
62
+ b1.click(
63
+ transcribe,
64
+ inputs=[audio_file],
65
+ outputs=[output_file],
66
+ )
67
+
68
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ffmpeg
2
+ libsndfile1
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torchaudio
2
+ nemo_toolkit[asr]==1.19.0
3
+ hydra-core
4
+ wandb