Spaces:
Runtime error
Runtime error
Pavankalyan
commited on
Commit
•
15c9fcc
1
Parent(s):
9f0f2c6
added pretrained model
Browse files- app.py +54 -0
- pretrained_ljs.pth +3 -0
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
import IPython.display as ipd
|
7 |
+
|
8 |
+
import os
|
9 |
+
import json
|
10 |
+
import math
|
11 |
+
import torch
|
12 |
+
from torch import nn
|
13 |
+
from torch.nn import functional as F
|
14 |
+
from torch.utils.data import DataLoader
|
15 |
+
|
16 |
+
import commons
|
17 |
+
import utils
|
18 |
+
from data_utils import TextAudioLoader, TextAudioCollate, TextAudioSpeakerLoader, TextAudioSpeakerCollate
|
19 |
+
from models import SynthesizerTrn
|
20 |
+
from text.symbols import symbols
|
21 |
+
from text import text_to_sequence
|
22 |
+
|
23 |
+
from scipy.io.wavfile import write
|
24 |
+
|
25 |
+
|
26 |
+
def get_text(text, hps):
|
27 |
+
text_norm = text_to_sequence(text, hps.data.text_cleaners)
|
28 |
+
if hps.data.add_blank:
|
29 |
+
text_norm = commons.intersperse(text_norm, 0)
|
30 |
+
text_norm = torch.LongTensor(text_norm)
|
31 |
+
return text_norm
|
32 |
+
|
33 |
+
hps = utils.get_hparams_from_file("/ljs_base.json")
|
34 |
+
|
35 |
+
net_g = SynthesizerTrn(
|
36 |
+
len(symbols),
|
37 |
+
hps.data.filter_length // 2 + 1,
|
38 |
+
hps.train.segment_size // hps.data.hop_length,
|
39 |
+
**hps.model).cuda()
|
40 |
+
_ = net_g.eval()
|
41 |
+
|
42 |
+
_ = utils.load_checkpoint("/pretrained_ljs.pth", net_g, None)
|
43 |
+
|
44 |
+
|
45 |
+
def transcribe(text):
|
46 |
+
stn_tst = get_text(text, hps)
|
47 |
+
with torch.no_grad():
|
48 |
+
x_tst = stn_tst.cuda().unsqueeze(0)
|
49 |
+
x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).cuda()
|
50 |
+
audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()
|
51 |
+
return hps.data.sampling_rate, audio
|
52 |
+
|
53 |
+
get_intent = gr.Interface(fn = transcribe,
|
54 |
+
inputs="textbox", outputs="audio").launch()
|
pretrained_ljs.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c94fb49d08ba90c598de16e7d5dec8d26bf225c1cf193a4fba05eb2dbda5a561
|
3 |
+
size 145599717
|