Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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):
|
| 31 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
| 32 |
+
title = int(title)
|
| 33 |
+
project_name = "Unnamed"
|
| 34 |
+
model_path = ckpt_temp_file
|
| 35 |
+
config_path= config_temp_file
|
| 36 |
+
hubert_gpu=True
|
| 37 |
+
svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
|
| 38 |
+
print('model loaded')
|
| 39 |
+
wav_fn = audio_temp_file
|
| 40 |
+
demoaudio, sr = librosa.load(wav_fn)
|
| 41 |
+
key = title # 音高调整,支持正负(半音)
|
| 42 |
+
# 加速倍数
|
| 43 |
+
pndm_speedup = 20
|
| 44 |
+
wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
|
| 45 |
+
|
| 46 |
+
# Show the spinner and run the run_clip function inside the 'with' block
|
| 47 |
+
with st.spinner("Rendering Audio..."):
|
| 48 |
+
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,
|
| 49 |
+
use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
|
| 50 |
+
clip_completed = True
|
| 51 |
+
if clip_completed:
|
| 52 |
+
# If the 'run_clip' function has completed, use the st.audio function to show an audio player for the file stored in the 'wav_gen' variable
|
| 53 |
+
st.audio(wav_gen)
|
| 54 |
+
|
| 55 |
+
#######################################################
|
| 56 |
+
st.set_page_config(
|
| 57 |
+
page_title="DiffSVC Render",
|
| 58 |
+
page_icon="🧊",
|
| 59 |
+
initial_sidebar_state="expanded",
|
| 60 |
+
)
|
| 61 |
+
############
|
| 62 |
+
st.title('DIFF-SVC Render')
|
| 63 |
+
|
| 64 |
+
###CKPT LOADER
|
| 65 |
+
|
| 66 |
+
ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
|
| 67 |
+
# Check if user uploaded a CKPT file
|
| 68 |
+
if ckpt is not None:
|
| 69 |
+
#TEMP FUNCTION
|
| 70 |
+
ckpt_temp_file = os.path.join(temp_dir.name, "ckpt_temp_file.ckpt")
|
| 71 |
+
with open(ckpt_temp_file, "wb") as temp:
|
| 72 |
+
bytes_data = ckpt.getvalue()
|
| 73 |
+
temp.write(bytes_data)
|
| 74 |
+
st.success("File saved to: {}".format(ckpt_temp_file))
|
| 75 |
+
|
| 76 |
+
# Print the temporary file name
|
| 77 |
+
print(temp.name)
|
| 78 |
+
st.success("File saved to: {}".format(ckpt_temp_file))
|
| 79 |
+
|
| 80 |
+
# Display the file path
|
| 81 |
+
if "ckpt_temp_file" in locals():
|
| 82 |
+
st.success("File saved to: {}".format(ckpt_temp_file))
|
| 83 |
+
|
| 84 |
+
# File uploader
|
| 85 |
+
config = st.file_uploader("Choose your config", type= 'yaml')
|
| 86 |
+
|
| 87 |
+
# Check if user uploaded a config file
|
| 88 |
+
if config is not None:
|
| 89 |
+
#TEMP FUNCTION
|
| 90 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
|
| 91 |
+
# Get the file contents as bytes
|
| 92 |
+
bytes_data = config.getvalue()
|
| 93 |
+
# Write the bytes to the temporary file
|
| 94 |
+
temp.write(bytes_data)
|
| 95 |
+
config_temp_file = temp.name
|
| 96 |
+
# Print the temporary file name
|
| 97 |
+
print(temp.name)
|
| 98 |
+
|
| 99 |
+
# Display the file path
|
| 100 |
+
if "config_temp_file" in locals():
|
| 101 |
+
st.success("File saved to: {}".format(config_temp_file))
|
| 102 |
+
|
| 103 |
+
audio = st.file_uploader("Choose your audio", type=["wav", "mp3"])
|
| 104 |
+
|
| 105 |
+
# Check if user uploaded an audio file
|
| 106 |
+
if audio is not None:
|
| 107 |
+
#TEMP FUNCTION
|
| 108 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
|
| 109 |
+
# Get the file contents as bytes
|
| 110 |
+
bytes_data = audio.getvalue()
|
| 111 |
+
# Write the bytes to the temporary file
|
| 112 |
+
temp.write(bytes_data)
|
| 113 |
+
audio_temp_file = temp.name
|
| 114 |
+
# Print the temporary file name
|
| 115 |
+
print(temp.name)
|
| 116 |
+
|
| 117 |
+
# Display the file path
|
| 118 |
+
if "audio_temp_file" in locals():
|
| 119 |
+
st.success("File saved to: {}".format(audio_temp_file))
|
| 120 |
+
# Add a text input for the title with a default value of 0
|
| 121 |
+
title = st.text_input("Key", value="0")
|
| 122 |
+
# Add a button to start the rendering process
|
| 123 |
+
if st.button("Render audio"):
|
| 124 |
+
render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title)
|