|
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 = os.path.expanduser("~/app") |
|
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): |
|
logging.getLogger('numba').setLevel(logging.WARNING) |
|
title = int(title) |
|
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' |
|
|
|
|
|
with st.spinner("Rendering Audio..."): |
|
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, |
|
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') |
|
|
|
|
|
with tempfile.TemporaryDirectory(dir=os.path.expanduser("~/app")) as temp_dir: |
|
ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt') |
|
|
|
if ckpt is not None: |
|
|
|
with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp: |
|
|
|
bytes_data = ckpt.getvalue() |
|
|
|
temp.write(bytes_data) |
|
ckpt_temp_file = temp.name |
|
|
|
print(temp.name) |
|
|
|
|
|
if "ckpt_temp_file" in locals(): |
|
st.success("File saved to: {}".format(ckpt_temp_file)) |
|
|
|
|
|
config = st.file_uploader("Choose your config", type= 'yaml') |
|
|
|
|
|
if config is not None: |
|
|
|
with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp: |
|
|
|
bytes_data = config.getvalue() |
|
|
|
temp.write(bytes_data) |
|
config_temp_file = temp.name |
|
|
|
print(temp.name) |
|
|
|
|
|
if "config_temp_file" in locals(): |
|
st.success("File saved to: {}".format(config_temp_file)) |
|
|
|
audio = st.file_uploader("Choose your audio", type=["wav", "mp3"]) |
|
|
|
|
|
if audio is not None: |
|
|
|
with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp: |
|
|
|
bytes_data = audio.getvalue() |
|
|
|
temp.write(bytes_data) |
|
audio_temp_file = temp.name |
|
|
|
print(temp.name) |
|
|
|
|
|
if "audio_temp_file" in locals(): |
|
st.success("File saved to: {}".format(audio_temp_file)) |
|
|
|
title = st.text_input("Key", value="0") |
|
|
|
if st.button("Render audio"): |
|
render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title) |