Spaces:
Sleeping
Sleeping
Vladimir Alabov
commited on
Commit
•
ff5d419
1
Parent(s):
dd17486
Add greet #2
Browse files
app.py
CHANGED
@@ -1,85 +1,6 @@
|
|
1 |
import os
|
2 |
import io
|
3 |
import gradio as gr
|
4 |
-
import librosa
|
5 |
-
import numpy as np
|
6 |
-
import logging
|
7 |
-
import soundfile
|
8 |
-
import asyncio
|
9 |
-
import argparse
|
10 |
-
import gradio.processing_utils as gr_processing_utils
|
11 |
-
logging.getLogger('numba').setLevel(logging.WARNING)
|
12 |
-
logging.getLogger('markdown_it').setLevel(logging.WARNING)
|
13 |
-
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
14 |
-
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
15 |
-
|
16 |
-
limitation = os.getenv("SYSTEM") == "spaces" # limit audio length in huggingface spaces
|
17 |
-
|
18 |
-
audio_postprocess_ori = gr.Audio.postprocess
|
19 |
-
|
20 |
-
def audio_postprocess(self, y):
|
21 |
-
data = audio_postprocess_ori(self, y)
|
22 |
-
if data is None:
|
23 |
-
return None
|
24 |
-
return gr_processing_utils.encode_url_or_file_to_base64(data["name"])
|
25 |
-
|
26 |
-
gr.Audio.postprocess = audio_postprocess
|
27 |
-
def create_vc_fn(model, sid):
|
28 |
-
def vc_fn(input_audio, vc_transform, auto_f0):
|
29 |
-
if input_audio is None:
|
30 |
-
return "You need to upload an audio", None
|
31 |
-
sampling_rate, audio = input_audio
|
32 |
-
duration = audio.shape[0] / sampling_rate
|
33 |
-
if duration > 20 and limitation:
|
34 |
-
return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
|
35 |
-
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
36 |
-
if len(audio.shape) > 1:
|
37 |
-
audio = librosa.to_mono(audio.transpose(1, 0))
|
38 |
-
if sampling_rate != 16000:
|
39 |
-
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
40 |
-
raw_path = io.BytesIO()
|
41 |
-
soundfile.write(raw_path, audio, 16000, format="wav")
|
42 |
-
raw_path.seek(0)
|
43 |
-
out_audio, out_sr = model.infer(sid, vc_transform, raw_path,
|
44 |
-
auto_predict_f0=auto_f0,
|
45 |
-
)
|
46 |
-
return "Success", (44100, out_audio.cpu().numpy())
|
47 |
-
return vc_fn
|
48 |
-
|
49 |
-
if __name__ == '__main__':
|
50 |
-
parser = argparse.ArgumentParser()
|
51 |
-
parser.add_argument('--device', type=str, default='cpu')
|
52 |
-
parser.add_argument('--api', action="store_true", default=False)
|
53 |
-
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
54 |
-
args = parser.parse_args()
|
55 |
-
models = []
|
56 |
-
voices = []
|
57 |
-
for f in os.listdir("models"):
|
58 |
-
name = f
|
59 |
-
# = Svc(fr"models/{f}/{f}.pth", f"models/{f}/config.json", device=args.device)
|
60 |
-
#cover = f"models/{f}/cover.png" if os.path.exists(f"models/{f}/cover.png") else None
|
61 |
-
#models.append((name, cover, create_vc_fn(model, name)))
|
62 |
-
|
63 |
-
# !svc infer {NAME}.wav -c config.json -m G_riri_220.pth
|
64 |
-
# display(Audio(f"{NAME}.out.wav", autoplay=True))
|
65 |
-
with gr.Blocks() as app:
|
66 |
-
with gr.Tabs():
|
67 |
-
for (name, cover, vc_fn) in models:
|
68 |
-
with gr.TabItem(name):
|
69 |
-
with gr.Row():
|
70 |
-
with gr.Column():
|
71 |
-
vc_input = gr.Audio(label="Input audio"+' (less than 20 seconds)' if limitation else '')
|
72 |
-
vc_transform = gr.Number(label="vc_transform", value=0)
|
73 |
-
auto_f0 = gr.Checkbox(label="auto_f0", value=False)
|
74 |
-
vc_submit = gr.Button("Generate", variant="primary")
|
75 |
-
with gr.Column():
|
76 |
-
vc_output1 = gr.Textbox(label="Output Message")
|
77 |
-
vc_output2 = gr.Audio(label="Output Audio")
|
78 |
-
vc_submit.click(vc_fn, [vc_input, vc_transform, auto_f0], [vc_output1, vc_output2])
|
79 |
-
app.queue(concurrency_count=1, api_open=args.api).launch(share=args.share)
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
|
84 |
def greet(name):
|
85 |
return "Hello " + name + "!!"
|
|
|
1 |
import os
|
2 |
import io
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def greet(name):
|
6 |
return "Hello " + name + "!!"
|