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

Update streamlitpoe.py

Browse files
Files changed (1) hide show
  1. streamlitpoe.py +80 -56
streamlitpoe.py CHANGED
@@ -6,13 +6,46 @@ import json
6
  import tempfile
7
  import shutil
8
  temp_dir = tempfile.mkdtemp()
9
- ##### PAGE CONFIG
10
- def printthings():
11
- print(ckpt)
12
- print(config)
13
- print(audio)
14
- print(gflag)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
16
  st.set_page_config(
17
  page_title="DiffSVC Render",
18
  page_icon="🧊",
@@ -21,56 +54,47 @@ st.set_page_config(
21
  ############
22
  st.title('DIFF-SVC Render')
23
 
24
- col1, col2 = st.columns([2, 1])
25
-
26
- with col1:
27
- ###CKPT LOADER
28
- ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
29
- # Check if user uploaded a CKPT file
30
- if ckpt is not None:
31
- #TEMP FUNCTION
32
- with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
33
- # Get the file contents as bytes
34
- bytes_data = ckpt.getvalue()
35
-
36
- # Write the bytes to the temporary file
37
- temp.write(bytes_data)
38
-
39
- # Print the temporary file name
40
- print(temp.name)
41
-
42
-
43
- ###CONFIG LOADER
44
- config = st.file_uploader("Choose your config", type= 'yaml')
45
- if config is not None:
46
- #TEMP FUNCTION
47
- with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
48
- # Get the file contents as bytes
49
- bytes_data = config.getvalue()
50
-
51
- # Write the bytes to the temporary file
52
- temp.write(bytes_data)
53
-
54
- # Print the temporary file name
55
- print(temp.name)
56
- ##WAV LOADER
57
- audio = st.file_uploader("Choose your audio", type= 'wav' or 'mp3')
58
- if audio is not None:
59
- #TEMP FUNCTION
60
- with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
61
- # Get the file contents as bytes
62
- bytes_data = audio.getvalue()
63
 
64
- # Write the bytes to the temporary file
65
- temp.write(bytes_data)
 
 
 
 
 
 
 
 
 
 
66
 
67
- # Print the temporary file name
68
- print(temp.name)
69
- gflag = st.slider('Gender Flag', 0.80, 1.20, 1.00)
70
-
71
- with col2:
72
- ###DOWNLOAD
73
- text_contents = '''This is some text'''
74
- st.download_button('Download Rendered File', text_contents)
75
- st.button('Test', on_click=printthings)
 
 
 
 
 
76
 
 
 
 
6
  import tempfile
7
  import shutil
8
  temp_dir = tempfile.mkdtemp()
9
+ global ckpt_temp_file
10
+ global audio_temp_file
11
+ global config_temp_file
12
+ ###################################################
13
+ from utils.hparams import hparams
14
+ from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
15
+ import numpy as np
16
+ import matplotlib.pyplot as plt
17
+ import IPython.display as ipd
18
+ import utils
19
+ import librosa
20
+ import torchcrepe
21
+ from infer import *
22
+ import logging
23
+ from infer_tools.infer_tool import *
24
+ import io
25
+ clip_completed = False
26
+ def render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title):
27
+ logging.getLogger('numba').setLevel(logging.WARNING)
28
+ title = int(title)
29
+ project_name = "Unnamed"
30
+ model_path = ckpt_temp_file
31
+ config_path= config_temp_file
32
+ hubert_gpu=True
33
+ svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
34
+ print('model loaded')
35
+ wav_fn = audio_temp_file
36
+ demoaudio, sr = librosa.load(wav_fn)
37
+ key = title # 音高调整,支持正负(半音)
38
+ # 加速倍数
39
 
40
+ pndm_speedup = 20
41
+ wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
42
+ 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,
43
+ use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
44
+ clip_completed = True
45
+ if clip_completed:
46
+ # 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
47
+ st.audio(wav_gen)
48
+ #######################################################
49
  st.set_page_config(
50
  page_title="DiffSVC Render",
51
  page_icon="🧊",
 
54
  ############
55
  st.title('DIFF-SVC Render')
56
 
57
+ ###CKPT LOADER
58
+ ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
59
+ # Check if user uploaded a CKPT file
60
+ if ckpt is not None:
61
+ #TEMP FUNCTION
62
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
63
+ # Get the file contents as bytes
64
+ bytes_data = ckpt.getvalue()
65
+ # Write the bytes to the temporary file
66
+ temp.write(bytes_data)
67
+ ckpt_temp_file = temp.name
68
+ # Print the temporary file name
69
+ print(temp.name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ ###CONFIG LOADER
72
+ config = st.file_uploader("Choose your config", type= 'yaml')
73
+ if config is not None:
74
+ #TEMP FUNCTION
75
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
76
+ # Get the file contents as bytes
77
+ bytes_data = config.getvalue()
78
+ # Write the bytes to the temporary file
79
+ temp.write(bytes_data)
80
+ config_temp_file = temp.name
81
+ # Print the temporary file name
82
+ print(temp.name)
83
 
84
+ ##WAV LOADER
85
+ audio = st.file_uploader("Choose your audio", type= 'wav' or 'mp3')
86
+ if audio is not None:
87
+ #TEMP FUNCTION
88
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
89
+ # Get the file contents as bytes
90
+ bytes_data = audio.getvalue()
91
+ # Write the bytes to the temporary file
92
+ temp.write(bytes_data)
93
+ audio_temp_file = temp.name
94
+ # Print the temporary file name
95
+ print(temp.name)
96
+ title = st.text_input('Key', '0')
97
+ gflag = st.slider('Gender Flag', 0.80, 1.20, 1.00)
98
 
99
+ ###DOWNLOAD
100
+ st.button('Render', on_click=render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title))