Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,2 +1,126 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
import tempfile
|
8 |
+
import shutil
|
9 |
+
import requests
|
10 |
+
from pathlib import Path
|
11 |
+
temp_dir = tempfile.TemporaryDirectory()
|
12 |
+
global ckpt_temp_file
|
13 |
+
global audio_temp_file
|
14 |
+
global config_temp_file
|
15 |
+
###################################################
|
16 |
+
from utils.hparams import hparams
|
17 |
+
from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
|
18 |
+
import numpy as np
|
19 |
+
import matplotlib.pyplot as plt
|
20 |
+
import IPython.display as ipd
|
21 |
+
import utils
|
22 |
+
import librosa
|
23 |
+
import torchcrepe
|
24 |
+
from infer import *
|
25 |
+
import logging
|
26 |
+
from infer_tools.infer_tool import *
|
27 |
+
import io
|
28 |
+
|
29 |
+
clip_completed = False
|
30 |
+
def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2):
|
31 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
32 |
+
title = int(title)
|
33 |
+
title2 = int(title2)
|
34 |
+
|
35 |
+
project_name = "Unnamed"
|
36 |
+
model_path = ckpt_temp_file
|
37 |
+
config_path= config_temp_file
|
38 |
+
hubert_gpu=True
|
39 |
+
svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
|
40 |
+
print('model loaded')
|
41 |
+
wav_fn = audio_temp_file
|
42 |
+
demoaudio, sr = librosa.load(wav_fn)
|
43 |
+
key = title # 音高调整,支持正负(半音)
|
44 |
+
# 加速倍数
|
45 |
+
pndm_speedup = 20
|
46 |
+
wav_gen='queeeeee.wav'
|
47 |
+
|
48 |
+
# Show the spinner and run the run_clip function inside the 'with' block
|
49 |
+
with st.spinner("Rendering Audio..."):
|
50 |
+
f0_tst, f0_pred, audio = run_clip(svc_model,file_path=wav_fn, key=key, acc=title2, use_crepe=True, use_pe=True, thre=0.05,
|
51 |
+
use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
|
52 |
+
clip_completed = True
|
53 |
+
if clip_completed:
|
54 |
+
|
55 |
+
st.audio(wav_gen)
|
56 |
+
|
57 |
+
#######################################################
|
58 |
+
st.set_page_config(
|
59 |
+
page_title="DiffSVC Render",
|
60 |
+
page_icon="🧊",
|
61 |
+
initial_sidebar_state="expanded",
|
62 |
+
)
|
63 |
+
############
|
64 |
+
st.title('DIFF-SVC Render')
|
65 |
+
|
66 |
+
###CKPT LOADER
|
67 |
+
ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
|
68 |
+
# Check if user uploaded a CKPT file
|
69 |
+
if ckpt is not None:
|
70 |
+
#TEMP FUNCTION
|
71 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
|
72 |
+
# Get the file contents as bytes
|
73 |
+
bytes_data = ckpt.getvalue()
|
74 |
+
# Write the bytes to the temporary file
|
75 |
+
temp.write(bytes_data)
|
76 |
+
ckpt_temp_file = temp.name
|
77 |
+
# Print the temporary file name
|
78 |
+
print(temp.name)
|
79 |
+
# Display the file path
|
80 |
+
if "ckpt_temp_file" in locals():
|
81 |
+
st.success("File saved to: {}".format(ckpt_temp_file))
|
82 |
+
# File uploader
|
83 |
+
config = st.file_uploader("Choose your config", type= 'yaml')
|
84 |
+
# Check if user uploaded a config file
|
85 |
+
if config is not None:
|
86 |
+
#TEMP FUNCTION
|
87 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
|
88 |
+
# Get the file contents as bytes
|
89 |
+
bytes_data = config.getvalue()
|
90 |
+
# Write the bytes to the temporary file
|
91 |
+
temp.write(bytes_data)
|
92 |
+
config_temp_file = temp.name
|
93 |
+
# Print the temporary file name
|
94 |
+
print(temp.name)
|
95 |
+
# Display the file path
|
96 |
+
if "config_temp_file" in locals():
|
97 |
+
st.success("File saved to: {}".format(config_temp_file))
|
98 |
+
audio = st.file_uploader("Choose your audio", type=["wav"])
|
99 |
+
# Check if user uploaded an audio file
|
100 |
+
if audio is not None:
|
101 |
+
#EMP FUNCTION
|
102 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
|
103 |
+
# Get the file contents as bytes
|
104 |
+
bytes_data = audio.getvalue()
|
105 |
+
# Write the bytes to the temporary file
|
106 |
+
temp.write(bytes_data)
|
107 |
+
audio_temp_file = temp.name
|
108 |
+
# Print the temporary file name
|
109 |
+
print(temp.name)
|
110 |
+
# Display the file path
|
111 |
+
if "audio_temp_file" in locals():
|
112 |
+
st.success("File saved to: {}".format(audio_temp_file))
|
113 |
+
# Add a text input for the title with a default value of 0
|
114 |
+
title = st.text_input("Key", value="0")
|
115 |
+
title2 = st.text_input("Speedup", value="20")
|
116 |
+
# Add a button to start the rendering process
|
117 |
+
# Add a button to start the rendering process
|
118 |
+
# if st.button("Render audio"):
|
119 |
+
# password = st.text_input("Enter password")
|
120 |
+
# with open("network/hubert/Hifi.txt", "r") as f:
|
121 |
+
# correct_password = f.read().strip()
|
122 |
+
# if password == correct_password:
|
123 |
+
# render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2)
|
124 |
+
#
|
125 |
+
# else:
|
126 |
+
# st.error("Incorrect password")
|