mitudesk/uma_diffsvc
0
1import streamlit as st2import pandas as pd3import numpy as np4import matplotlib.pyplot as plt5import json6import os7import tempfile8import shutil9import requests10from pathlib import Path11temp_dir = os.path.expanduser("/~app")12global ckpt_temp_file13global audio_temp_file14global config_temp_file15###################################################16from utils.hparams import hparams17from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe18import numpy as np19import matplotlib.pyplot as plt20import IPython.display as ipd21import utils22import librosa23import torchcrepe24from infer import *25import logging26from infer_tools.infer_tool import *27import io28 29clip_completed = False30def 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_file35 config_path= config_temp_file36 hubert_gpu=True37 svc_model = Svc(project_name,config_path,hubert_gpu, model_path)38 print('model loaded')39 wav_fn = audio_temp_file40 demoaudio, sr = librosa.load(wav_fn)41 key = title # 音高调整,支持正负(半音)42 # 加速倍数43 pndm_speedup = 2044 wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩45 46 # Show the spinner and run the run_clip function inside the 'with' block47 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 = True51 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' variable53 st.audio(wav_gen)54 55#######################################################56st.set_page_config(57 page_title="DiffSVC Render",58 page_icon="🧊",59 initial_sidebar_state="expanded",60)61############62st.title('DIFF-SVC Render')63 64###CKPT LOADER65with tempfile.TemporaryDirectory(dir=os.path.expanduser("/~app")) as temp_dir:66 ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')67 # Check if user uploaded a CKPT file68 if ckpt is not None:69 #TEMP FUNCTION70 with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False, dir=temp_dir) as temp:71 # Get the file contents as bytes72 bytes_data = ckpt.getvalue()73 # Write the bytes to the temporary file74 temp.write(bytes_data)75 ckpt_temp_file = temp.name76 # Print the temporary file name77 print(temp.name)78 79 # Display the file path80 if "ckpt_temp_file" in locals():81 st.success("File saved to: {}".format(ckpt_temp_file))82 83 # File uploader84 config = st.file_uploader("Choose your config", type= 'yaml')85 86 # Check if user uploaded a config file87 if config is not None:88 #TEMP FUNCTION89 with tempfile.NamedTemporaryFile(mode="w", suffix='.yaml', delete=False, dir=temp_dir) as temp:90 # Get the file contents as bytes91 bytes_data = config.getvalue()92 # Write the bytes to the temporary file93 temp.write(bytes_data)94 config_temp_file = temp.name95 # Print the temporary file name96 print(temp.name)97 98 # Display the file path99 if "config_temp_file" in locals():100 st.success("File saved to: {}".format(config_temp_file))101 102 audio = st.file_uploader("Choose your audio", type=["wav", "mp3"])103 104 # Check if user uploaded an audio file105 if audio is not None:106 #TEMP FUNCTION107 with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False, dir=temp_dir) as temp:108 # Get the file contents as bytes109 bytes_data = audio.getvalue()110 # Write the bytes to the temporary file111 temp.write(bytes_data)112 audio_temp_file = temp.name113 # Print the temporary file name114 print(temp.name)115 116# Display the file path117 if "audio_temp_file" in locals():118 st.success("File saved to: {}".format(audio_temp_file))119# Add a text input for the title with a default value of 0120title = st.text_input("Key", value="0")121# Add a button to start the rendering process122if st.button("Render audio"):123 render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title)