Kangarroar commited on
Commit
afd85cb
1 Parent(s): dd25ac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -78
app.py CHANGED
@@ -1,4 +1,17 @@
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,93 +24,100 @@ from infer import *
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
- global wav_gen
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 = 0
33
-
34
  pndm_speedup = 20
35
  wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
36
- 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,
37
- use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
38
- # Play the audio file in the output component
39
- output_audio.play(wav_gen)
40
- return wav_gen
41
- ############################################
42
- # Create the output components
43
- #Transform ckpt binary into .ckpt
44
- def transform_binary(ckpt_file):
45
- # Create a temporary file and write the binary contents to it
46
- temp_file = tempfile.NamedTemporaryFile(suffix='.ckpt', delete=False)
47
- temp_file.write(ckpt_file)
48
- print("CKPT Path is:", temp_file.name)
49
- global ckpt
50
- ckpt = temp_file.name
51
 
52
- print(ckpt)
53
- print(ckpt)
54
- print(ckpt)
55
- return temp_file.name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- #Transform yaml binary into .yaml
58
- def transform_binary2(yaml_file):
59
- # Create a temporary file and write the binary contents to it
60
- temp_file = tempfile.NamedTemporaryFile(suffix='.yaml', delete=False)
61
- temp_file.write(yaml_file)
62
- print("YAML Path is:", temp_file.name)
63
- global yaml
64
- yaml = temp_file.name
65
- print(yaml)
66
- print(yaml)
67
- return temp_file.name
68
 
69
- #Play audio
70
- def play(audio_file):
71
- print(audio_file)
72
- upload_input = gr.inputs.File()
73
- output_label = gr.outputs.Label()
74
 
75
- demo = gr.Blocks()
76
- with demo:
77
- gr.Markdown("# **<p align='center'>DIFF-SVC Inference</p>**")
 
 
 
 
 
 
 
 
78
 
79
- gr.Markdown(
80
- """
81
- <p style='text-align: center'>
82
- Render whatever model you want with this space!
83
- </p>
84
- """
85
- )
86
- ckpt_file = gr.File(label= 'Load your CKPT', type="binary")
87
- yaml_file = gr.File(label= 'Load your YAML', type="binary")
88
- audio_file = gr.Audio(label = 'Load your WAV', type="filepath")
89
- #Button 1
90
- b1 = gr.Button("Decompile CKPT")
91
- b1.click(transform_binary, inputs=ckpt_file)
92
- #Button 2
93
- b2 = gr.Button("Decompile YAML")
94
- b2.click(transform_binary2, inputs=yaml_file)
95
- #Button 4
96
- b4 = gr.Button("Render")
97
- b4.click(fn=render_audio, inputs=[audio_file])
98
- def spam():
99
- print(yaml)
100
- print(ckpt)
101
- #b5 = gr.Button("SPAM ME")
102
- #b5.click(fn=spam)
103
- demo.launch()
 
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
  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
  pndm_speedup = 20
42
  wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ # Show the spinner and run the run_clip function inside the 'with' block
45
+ with st.spinner("Rendering Audio..."):
46
+ 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,
47
+ use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
48
+ clip_completed = True
49
+ if clip_completed:
50
+ # 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
51
+ st.audio(wav_gen)
52
+
53
+ #######################################################
54
+ st.set_page_config(
55
+ page_title="DiffSVC Render",
56
+ page_icon="🧊",
57
+ initial_sidebar_state="expanded",
58
+ )
59
+ ############
60
+ st.title('DIFF-SVC Render')
61
+
62
+ ###CKPT LOADER
63
+ # File uploader
64
+ ckpt = st.file_uploader("Choose your CKPT", type= 'ckpt')
65
+
66
+ # Check if user uploaded a CKPT file
67
+ if ckpt is not None:
68
+ #TEMP FUNCTION
69
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.ckpt', delete=False) as temp:
70
+ # Get the file contents as bytes
71
+ bytes_data = ckpt.getvalue()
72
+ # Write the bytes to the temporary file
73
+ temp.write(bytes_data)
74
+ ckpt_temp_file = temp.name
75
+ # Print the temporary file name
76
+ print(temp.name)
77
+
78
+ # Display the file path
79
+ if "ckpt_temp_file" in locals():
80
+ st.success("File saved to: {}".format(ckpt_temp_file))
81
+
82
+ # File uploader
83
+ config = st.file_uploader("Choose your config", type= 'yaml')
84
+
85
+ # Check if user uploaded a config file
86
+ if config is not None:
87
+ #TEMP FUNCTION
88
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.yaml', delete=False) as temp:
89
+ # Get the file contents as bytes
90
+ bytes_data = config.getvalue()
91
+ # Write the bytes to the temporary file
92
+ temp.write(bytes_data)
93
+ config_temp_file = temp.name
94
+ # Print the temporary file name
95
+ print(temp.name)
96
 
97
+ # Display the file path
98
+ if "config_temp_file" in locals():
99
+ st.success("File saved to: {}".format(config_temp_file))
 
 
 
 
 
 
 
 
100
 
101
+ # File uploader
102
+ audio = st.file_uploader("Choose your audio", type=["wav", "mp3"])
 
 
 
103
 
104
+ # Check if user uploaded an audio file
105
+ if audio is not None:
106
+ #TEMP FUNCTION
107
+ with tempfile.NamedTemporaryFile(mode="wb", suffix='.wav', delete=False) as temp:
108
+ # Get the file contents as bytes
109
+ bytes_data = audio.getvalue()
110
+ # Write the bytes to the temporary file
111
+ temp.write(bytes_data)
112
+ audio_temp_file = temp.name
113
+ # Print the temporary file name
114
+ print(temp.name)
115
 
116
+ # Display the file path
117
+ 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 0
120
+ title = st.text_input("Key", value="0")
121
+ # Add a button to start the rendering process
122
+ if st.button("Render audio"):
123
+ render_audio(ckpt_temp_file, config_temp_file, audio_temp_file, title)