Spaces:
Configuration error
Configuration error
Kangarroar
commited on
Commit
•
7f3294d
1
Parent(s):
9b28a56
Update initial.py
Browse files- initial.py +72 -93
initial.py
CHANGED
@@ -1,17 +1,4 @@
|
|
1 |
-
import
|
2 |
-
import pandas as pd
|
3 |
-
import numpy as np
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import json
|
6 |
-
import tempfile
|
7 |
-
import shutil
|
8 |
-
import requests
|
9 |
-
from pathlib import Path
|
10 |
-
temp_dir = tempfile.mkdtemp()
|
11 |
-
global ckpt_temp_file
|
12 |
-
global audio_temp_file
|
13 |
-
global config_temp_file
|
14 |
-
###################################################
|
15 |
from utils.hparams import hparams
|
16 |
from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
|
17 |
import numpy as np
|
@@ -24,99 +11,91 @@ from infer import *
|
|
24 |
import logging
|
25 |
from infer_tools.infer_tool import *
|
26 |
import io
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
30 |
-
|
|
|
31 |
project_name = "Unnamed"
|
32 |
-
model_path =
|
33 |
-
config_path=
|
34 |
hubert_gpu=True
|
35 |
svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
|
36 |
print('model loaded')
|
37 |
-
wav_fn =
|
38 |
demoaudio, sr = librosa.load(wav_fn)
|
39 |
-
key =
|
40 |
# 加速倍数
|
41 |
|
42 |
pndm_speedup = 20
|
43 |
wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
|
44 |
f0_tst, f0_pred, audio = run_clip(svc_model,file_path=wav_fn, key=key, acc=pndm_speedup, use_crepe=True, use_pe=True, thre=0.05,
|
45 |
use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
#ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
|
61 |
-
# Check if user uploaded a CKPT file
|
62 |
-
#if ckpt is not None:
|
63 |
-
#TEMP FUNCTION
|
64 |
-
# with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
|
65 |
-
# Get the file contents as bytes
|
66 |
-
# bytes_data = ckpt.getvalue()
|
67 |
-
# Write the bytes to the temporary file
|
68 |
-
# temp.write(bytes_data)
|
69 |
-
# ckpt_temp_file = temp.name
|
70 |
-
# Print the temporary file name
|
71 |
-
# print(temp.name)
|
72 |
-
# Create an input field for the URL
|
73 |
-
url = st.text_input("Enter the URL of the CKPT:")
|
74 |
-
|
75 |
-
# Download the file when the user presses Enter
|
76 |
-
if url:
|
77 |
-
response = requests.get(url)
|
78 |
-
file_content = response.content
|
79 |
-
file_name = url.split("/")[-1]
|
80 |
-
|
81 |
-
# Save the file to the local machine
|
82 |
-
with open(file_name, "wb") as f:
|
83 |
-
f.write(file_content)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
#
|
90 |
-
|
91 |
-
|
|
|
|
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
#TEMP FUNCTION
|
97 |
-
with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
|
98 |
-
# Get the file contents as bytes
|
99 |
-
bytes_data = config.getvalue()
|
100 |
-
# Write the bytes to the temporary file
|
101 |
-
temp.write(bytes_data)
|
102 |
-
config_temp_file = temp.name
|
103 |
-
# Print the temporary file name
|
104 |
-
print(temp.name)
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
#
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
122 |
-
st.button('Render', on_click=render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title))
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from utils.hparams import hparams
|
3 |
from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
|
4 |
import numpy as np
|
|
|
11 |
import logging
|
12 |
from infer_tools.infer_tool import *
|
13 |
import io
|
14 |
+
import tempfile
|
15 |
+
##Render function
|
16 |
+
def render_audio(audio_file):
|
17 |
+
print(audio_file)
|
18 |
+
print(ckpt)
|
19 |
+
print(yaml)
|
20 |
+
############
|
21 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
22 |
+
|
23 |
+
# 工程文件夹名,训练时用的那个
|
24 |
project_name = "Unnamed"
|
25 |
+
model_path = ckpt
|
26 |
+
config_path= yaml
|
27 |
hubert_gpu=True
|
28 |
svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
|
29 |
print('model loaded')
|
30 |
+
wav_fn = audio_file
|
31 |
demoaudio, sr = librosa.load(wav_fn)
|
32 |
+
key = -8 # 音高调整,支持正负(半音)
|
33 |
# 加速倍数
|
34 |
|
35 |
pndm_speedup = 20
|
36 |
wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
|
37 |
f0_tst, f0_pred, audio = run_clip(svc_model,file_path=wav_fn, key=key, acc=pndm_speedup, use_crepe=True, use_pe=True, thre=0.05,
|
38 |
use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
|
39 |
+
############################################
|
40 |
+
#Transform ckpt binary into .ckpt
|
41 |
+
def transform_binary(ckpt_file):
|
42 |
+
# Create a temporary file and write the binary contents to it
|
43 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.ckpt', delete=False)
|
44 |
+
temp_file.write(ckpt_file)
|
45 |
+
print("CKPT Path is:", temp_file.name)
|
46 |
+
global ckpt
|
47 |
+
ckpt = temp_file.name
|
48 |
+
|
49 |
+
print(ckpt)
|
50 |
+
print(ckpt)
|
51 |
+
print(ckpt)
|
52 |
+
return temp_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
#Transform yaml binary into .yaml
|
55 |
+
def transform_binary2(yaml_file):
|
56 |
+
# Create a temporary file and write the binary contents to it
|
57 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.yaml', delete=False)
|
58 |
+
temp_file.write(yaml_file)
|
59 |
+
print("YAML Path is:", temp_file.name)
|
60 |
+
global yaml
|
61 |
+
yaml = temp_file.name
|
62 |
+
print(yaml)
|
63 |
+
print(yaml)
|
64 |
+
return temp_file.name
|
65 |
|
66 |
+
#Play audio
|
67 |
+
def play(audio_file):
|
68 |
+
print(audio_file)
|
69 |
+
upload_input = gr.inputs.File()
|
70 |
+
output_label = gr.outputs.Label()
|
71 |
|
72 |
+
demo = gr.Blocks()
|
73 |
+
with demo:
|
74 |
+
gr.Markdown("# **<p align='center'>DIFF-SVC Inference</p>**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
gr.Markdown(
|
77 |
+
"""
|
78 |
+
<p style='text-align: center'>
|
79 |
+
Render whatever model you want with this space!
|
80 |
+
</p>
|
81 |
+
"""
|
82 |
+
)
|
83 |
+
ckpt_file = gr.File(label= 'Load your CKPT', type="binary")
|
84 |
+
yaml_file = gr.File(label= 'Load your YAML', type="binary")
|
85 |
+
audio_file = gr.Audio(label = 'Load your WAV', type="filepath")
|
86 |
+
#Button 1
|
87 |
+
b1 = gr.Button("Decompile CKPT")
|
88 |
+
b1.click(transform_binary, inputs=ckpt_file)
|
89 |
+
#Button 2
|
90 |
+
b2 = gr.Button("Decompile YAML")
|
91 |
+
b2.click(transform_binary2, inputs=yaml_file)
|
92 |
+
#Button 4
|
93 |
+
b4 = gr.Button("Render")
|
94 |
+
b4.click(fn=render_audio, inputs=[audio_file])
|
95 |
+
def spam():
|
96 |
+
print(yaml)
|
97 |
+
print(ckpt)
|
98 |
+
#b5 = gr.Button("SPAM ME")
|
99 |
+
#b5.click(fn=spam)
|
100 |
|
101 |
+
demo.launch()
|
|