Kangarroar commited on
Commit
c385861
1 Parent(s): 4d5522d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -13
app.py CHANGED
@@ -11,32 +11,63 @@ from infer import *
11
  import logging
12
  from infer_tools.infer_tool import *
13
  import io
 
 
14
  def render_audio(audio_file):
15
  print(audio_file)
 
 
16
  ############
17
  logging.getLogger('numba').setLevel(logging.WARNING)
18
 
19
  # 工程文件夹名,训练时用的那个
20
  project_name = "Unnamed"
21
- model_path = f'./checkpoints/Unnamed/model_ckpt_steps_192000.ckpt'
22
- config_path=f'./checkpoints/Unnamed/config.yaml'
23
  hubert_gpu=True
24
  svc_model = Svc(project_name,config_path,hubert_gpu, model_path)
25
  print('model loaded')
26
  wav_fn = audio_file
27
  demoaudio, sr = librosa.load(wav_fn)
28
- key = 0 # 音高调整,支持正负(半音)
29
  # 加速倍数
30
 
31
  pndm_speedup = 20
32
  wav_gen='queeeeee.wav'#直接改后缀可以保存不同格式音频,如flac可无损压缩
33
  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,
34
  use_gt_mel=False, add_noise_step=500,project_name=project_name,out_path=wav_gen)
35
-
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- def segment(audio):
39
- pass # Implement your image segmentation model here...
 
 
 
40
 
41
  demo = gr.Blocks()
42
  with demo:
@@ -49,12 +80,22 @@ with demo:
49
  </p>
50
  """
51
  )
52
- ckpt_file = gr.File(label= 'Load your CKPT', type="file")
53
- config_file = gr.File(label= 'Load your Config File', type="file")
54
  audio_file = gr.Audio(label = 'Load your WAV', type="filepath")
55
- gr.Slider(2, 20, value=4)
56
- b1 = gr.Button("Render")
57
- b1.click(fn=render_audio, inputs=audio_file)
58
-
 
 
 
 
 
 
 
 
 
 
59
 
60
- demo.launch()
 
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:
 
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()