Kangarroar commited on
Commit
28e3f26
1 Parent(s): 8359c9a

Update initial.py

Browse files
Files changed (1) hide show
  1. initial.py +121 -2
initial.py CHANGED
@@ -1,3 +1,122 @@
1
- import subprocess
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- subprocess.run(["streamlit", "run", "streamlitpoe.py", "--server.maxUploadSize", "1024"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 tempfile
7
+ import shutil
8
+ import requests
9
+ from pathlib import Path
10
+ temp_dir = tempfile.mkdtemp()
11
+ global ckpt_temp_file
12
+ global audio_temp_file
13
+ global config_temp_file
14
+ ###################################################
15
+ from utils.hparams import hparams
16
+ from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
17
+ import numpy as np
18
+ import matplotlib.pyplot as plt
19
+ import IPython.display as ipd
20
+ import utils
21
+ import librosa
22
+ import torchcrepe
23
+ from infer import *
24
+ import logging
25
+ from infer_tools.infer_tool import *
26
+ import io
27
+ clip_completed = False
28
+ def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title):
29
+ logging.getLogger('numba').setLevel(logging.WARNING)
30
+ title = int(title)
31
+ project_name = "Unnamed"
32
+ model_path = ckpt_temp_file
33
+ config_path= config_temp_file
34
+ hubert_gpu=True
35
+ svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
36
+ print('model loaded')
37
+ wav_fn = audio_temp_file
38
+ demoaudio, sr = librosa.load(wav_fn)
39
+ key = title # 音高调整,支持正负(半音)
40
+ # 加速倍数
41
 
42
+ pndm_speedup = 20
43
+ wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
44
+ 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,
45
+ use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
46
+ clip_completed = True
47
+ if clip_completed:
48
+ # 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
49
+ st.audio(wav_gen)
50
+ #######################################################
51
+ st.set_page_config(
52
+ page_title="DiffSVC Render",
53
+ page_icon="🧊",
54
+ initial_sidebar_state="expanded",
55
+ )
56
+ ############
57
+ st.title('DIFF-SVC Render')
58
+
59
+ ###CKPT LOADER
60
+ #ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
61
+ # Check if user uploaded a CKPT file
62
+ #if ckpt is not None:
63
+ #TEMP FUNCTION
64
+ # with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
65
+ # Get the file contents as bytes
66
+ # bytes_data = ckpt.getvalue()
67
+ # Write the bytes to the temporary file
68
+ # temp.write(bytes_data)
69
+ # ckpt_temp_file = temp.name
70
+ # Print the temporary file name
71
+ # print(temp.name)
72
+ # Create an input field for the URL
73
+ url = st.text_input("Enter the URL of the CKPT:")
74
+
75
+ # Download the file when the user presses Enter
76
+ if url:
77
+ response = requests.get(url)
78
+ file_content = response.content
79
+ file_name = url.split("/")[-1]
80
+
81
+ # Save the file to the local machine
82
+ with open(file_name, "wb") as f:
83
+ f.write(file_content)
84
+
85
+ # Save the file path as a variable
86
+ file_path = f.name
87
+ ckpt_temp_file = file_path
88
+
89
+ # Display the file path
90
+ if "file_path" in locals():
91
+ st.success("File saved to: {}".format(file_path))
92
+
93
+ ###CONFIG LOADER
94
+ config = st.file_uploader("Choose your config", type= 'yaml')
95
+ if config is not None:
96
+ #TEMP FUNCTION
97
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
98
+ # Get the file contents as bytes
99
+ bytes_data = config.getvalue()
100
+ # Write the bytes to the temporary file
101
+ temp.write(bytes_data)
102
+ config_temp_file = temp.name
103
+ # Print the temporary file name
104
+ print(temp.name)
105
+
106
+ ##WAV LOADER
107
+ audio = st.file_uploader("Choose your audio", type= 'wav' or 'mp3')
108
+ if audio is not None:
109
+ #TEMP FUNCTION
110
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
111
+ # Get the file contents as bytes
112
+ bytes_data = audio.getvalue()
113
+ # Write the bytes to the temporary file
114
+ temp.write(bytes_data)
115
+ audio_temp_file = temp.name
116
+ # Print the temporary file name
117
+ print(temp.name)
118
+ title = st.text_input('Key', '0')
119
+ gflag = st.slider('Gender Flag', 0.80, 1.20, 1.00)
120
+
121
+ ###DOWNLOAD
122
+ st.button('Render', on_click=render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title))