File size: 4,292 Bytes
79f7f06
2d0ef1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import json
import os
import tempfile
import shutil
import requests
from pathlib import Path
temp_dir = tempfile.TemporaryDirectory()
global ckpt_temp_file
global audio_temp_file
global config_temp_file
###################################################
from utils.hparams import hparams
from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
import utils
import librosa
import torchcrepe
from infer import *
import logging
from infer_tools.infer_tool import *
import io

clip_completed = False
def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2):
    logging.getLogger('numba').setLevel(logging.WARNING)
    title = int(title)
    title2 = int(title2)

    project_name = "Unnamed"
    model_path = ckpt_temp_file
    config_path= config_temp_file
    hubert_gpu=True
    svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
    print('model loaded')
    wav_fn = audio_temp_file
    demoaudio, sr = librosa.load(wav_fn)
    key = title # 音高调整,支持正负(半音)
    # 加速倍数
    pndm_speedup = 20
    wav_gen='queeeeee.wav'
    
    # Show the spinner and run the run_clip function inside the 'with' block
    with st.spinner("Rendering Audio..."):
      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,
                                        use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
    clip_completed = True
    if clip_completed:
    
        st.audio(wav_gen)

#######################################################
st.set_page_config(
    page_title="DiffSVC Render",
    page_icon="🧊",
    initial_sidebar_state="expanded",
)
############
st.title('DIFF-SVC Render')

###CKPT LOADER
ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
# Check if user uploaded a CKPT file
if ckpt is not None:
  #TEMP FUNCTION
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
    # Get the file contents as bytes
    bytes_data = ckpt.getvalue()
    # Write the bytes to the temporary file
    temp.write(bytes_data)
    ckpt_temp_file = temp.name
    # Print the temporary file name
    print(temp.name)
# Display the file path
if "ckpt_temp_file" in locals():
    st.success("File saved to: {}".format(ckpt_temp_file))
# File uploader
config = st.file_uploader("Choose your config", type= 'yaml')
# Check if user uploaded a config file
if config is not None:
  #TEMP FUNCTION
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
    # Get the file contents as bytes
    bytes_data = config.getvalue()
    # Write the bytes to the temporary file
    temp.write(bytes_data)
    config_temp_file = temp.name
    # Print the temporary file name
    print(temp.name)
# Display the file path
if "config_temp_file" in locals():
    st.success("File saved to: {}".format(config_temp_file))
audio = st.file_uploader("Choose your audio", type=["wav"])
# Check if user uploaded an audio file
if audio is not None:
#EMP FUNCTION
  with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
# Get the file contents as bytes
    bytes_data = audio.getvalue()
# Write the bytes to the temporary file
    temp.write(bytes_data)
    audio_temp_file = temp.name
# Print the temporary file name
    print(temp.name)
# Display the file path
if "audio_temp_file" in locals():
    st.success("File saved to: {}".format(audio_temp_file))
# Add a text input for the title with a default value of 0
title = st.text_input("Key", value="0")
title2 = st.text_input("Speedup", value="20")
# Add a button to start the rendering process
# Add a button to start the rendering process
# if st.button("Render audio"):
#     password = st.text_input("Enter password")
#     with open("network/hubert/Hifi.txt", "r") as f:
#         correct_password = f.read().strip()
#     if password == correct_password:
#         render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title, title2)
#   
#     else:
#         st.error("Incorrect password")