Kangarroar commited on
Commit
7f3294d
1 Parent(s): 9b28a56

Update initial.py

Browse files
Files changed (1) hide show
  1. initial.py +72 -93
initial.py CHANGED
@@ -1,17 +1,4 @@
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
@@ -24,99 +11,91 @@ 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))
 
1
+ import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from utils.hparams import hparams
3
  from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe
4
  import numpy as np
 
11
  import logging
12
  from infer_tools.infer_tool import *
13
  import io
14
+ import tempfile
15
+ ##Render function
16
+ def render_audio(audio_file):
17
+ print(audio_file)
18
+ print(ckpt)
19
+ print(yaml)
20
+ ############
21
  logging.getLogger('numba').setLevel(logging.WARNING)
22
+
23
+ # 工程文件夹名,训练时用的那个
24
  project_name = "Unnamed"
25
+ model_path = ckpt
26
+ config_path= yaml
27
  hubert_gpu=True
28
  svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
29
  print('model loaded')
30
+ wav_fn = audio_file
31
  demoaudio, sr = librosa.load(wav_fn)
32
+ key = -8 # 音高调整,支持正负(半音)
33
  # 加速倍数
34
 
35
  pndm_speedup = 20
36
  wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
37
  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,
38
  use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
39
+ ############################################
40
+ #Transform ckpt binary into .ckpt
41
+ def transform_binary(ckpt_file):
42
+ # Create a temporary file and write the binary contents to it
43
+ temp_file = tempfile.NamedTemporaryFile(suffix='.ckpt', delete=False)
44
+ temp_file.write(ckpt_file)
45
+ print("CKPT Path is:", temp_file.name)
46
+ global ckpt
47
+ ckpt = temp_file.name
48
+
49
+ print(ckpt)
50
+ print(ckpt)
51
+ print(ckpt)
52
+ return temp_file.name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
+ #Transform yaml binary into .yaml
55
+ def transform_binary2(yaml_file):
56
+ # Create a temporary file and write the binary contents to it
57
+ temp_file = tempfile.NamedTemporaryFile(suffix='.yaml', delete=False)
58
+ temp_file.write(yaml_file)
59
+ print("YAML Path is:", temp_file.name)
60
+ global yaml
61
+ yaml = temp_file.name
62
+ print(yaml)
63
+ print(yaml)
64
+ return temp_file.name
65
 
66
+ #Play audio
67
+ def play(audio_file):
68
+ print(audio_file)
69
+ upload_input = gr.inputs.File()
70
+ output_label = gr.outputs.Label()
71
 
72
+ demo = gr.Blocks()
73
+ with demo:
74
+ gr.Markdown("# **<p align='center'>DIFF-SVC Inference</p>**")
 
 
 
 
 
 
 
 
 
75
 
76
+ gr.Markdown(
77
+ """
78
+ <p style='text-align: center'>
79
+ Render whatever model you want with this space!
80
+ </p>
81
+ """
82
+ )
83
+ ckpt_file = gr.File(label= 'Load your CKPT', type="binary")
84
+ yaml_file = gr.File(label= 'Load your YAML', type="binary")
85
+ audio_file = gr.Audio(label = 'Load your WAV', type="filepath")
86
+ #Button 1
87
+ b1 = gr.Button("Decompile CKPT")
88
+ b1.click(transform_binary, inputs=ckpt_file)
89
+ #Button 2
90
+ b2 = gr.Button("Decompile YAML")
91
+ b2.click(transform_binary2, inputs=yaml_file)
92
+ #Button 4
93
+ b4 = gr.Button("Render")
94
+ b4.click(fn=render_audio, inputs=[audio_file])
95
+ def spam():
96
+ print(yaml)
97
+ print(ckpt)
98
+ #b5 = gr.Button("SPAM ME")
99
+ #b5.click(fn=spam)
100
 
101
+ demo.launch()