File size: 1,624 Bytes
061f670
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad29970
061f670
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from datetime import datetime, timedelta
import os

import gradio as gr
import torch
import nemo.collections.asr as nemo_asr
import wandb

MODEL_HISTORY_DAYS = 180
WANDB_ENTITY = os.environ.get("WANDB_ENTITY", "tarteel")
WANDB_PROJECT_NAME = os.environ.get("WANDB_PROJECT_NAME", "nemo-experiments")
MODEL_NAME = os.environ.get("MODEL_NAME", "CfCtcLg-SpeUni1024-DI-EATLDN-CA:v0")


def get_device():
    if torch.cuda.is_available():
        return "cuda"
    else:
        return "cpu"


# run = wandb.init(entity=WANDB_ENTITY, project=WANDB_PROJECT_NAME)
wandb_api = wandb.Api(overrides={"entity": WANDB_ENTITY})

artifact = wandb_api.artifact(f"{WANDB_ENTITY}/{WANDB_PROJECT_NAME}/{MODEL_NAME}")
artifact_dir = artifact.download()

# find the model (ending with .nemo) in the artifact directory
model_path = [
    os.path.join(root, file)
    for root, dirs, files in os.walk(artifact_dir)
    for file in files
    if file.endswith(".nemo")
][0]

model = nemo_asr.models.EncDecCTCModelBPE.restore_from(
    model_path, map_location=get_device()
)


def transcribe(audio_file):
    transcription_file = model.transcribe([audio_file])[0]
    return transcription_file


demo = gr.Blocks()

with demo:
    gr.Markdown(
        """
        # ﷽
        """
    )
    with gr.Row():
        audio_file = gr.Audio(source="upload", type="filepath", label="File")

    with gr.Row():
        output_file = gr.TextArea(label="Audio Transcription")

    b1 = gr.Button("Transcribe")

    b1.click(
        transcribe,
        inputs=[audio_file],
        outputs=[output_file],
        api_name="transcribe",
    )

demo.launch()