Yunshansongbai commited on
Commit
c5f4ba2
1 Parent(s): b3cb31e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -13,6 +13,7 @@ import requests
13
  import utils
14
  from spleeter import Separator
15
  import time
 
16
 
17
  build_dir=os.getcwd()
18
  if build_dir == "/home/aistudio":
@@ -22,7 +23,8 @@ model_dir=build_dir+'/trained_models'
22
 
23
  model_list_path = model_dir + "/model_list.txt"
24
 
25
- start_time = time.time()
 
26
 
27
  # 筛选出文件夹
28
  models = []
@@ -32,14 +34,15 @@ for filename in os.listdir(model_dir):
32
  models.append(os.path.splitext(filename)[0])
33
  cache_model = {}
34
 
35
- def reboot():
36
- global start_time
37
- if time.time() - start_time >= 3600: # 运行时间大于等于1小时
38
- gradio.alert("程序将重启...")
39
- os._exit(0)
40
  else:
41
- remaining_time = int(3600 - (time.time() - start_time)) # 计算剩余时间
42
- gradio.alert(f"距离下一次重启还剩{remaining_time}秒")
 
 
 
43
 
44
  def separate_fn(song_input):
45
  try:
@@ -137,6 +140,7 @@ def compose_fn(input_vocal,input_instrumental,mixing_ratio=0.5):
137
 
138
 
139
  app = gr.Blocks()
 
140
  with app:
141
  gr.Markdown('<h1 style="text-align: center;">SVC歌声转换全流程体验(伴奏分离,转换,混音)</h1>')
142
  with gr.Tabs() as tabs:
@@ -176,12 +180,13 @@ with app:
176
  song_output = gr.Audio(label="输出歌曲",interactive=False)
177
 
178
  with gr.TabItem("设置"):
179
- btn_reboot = gr.Button("重启程序", variant="primary")
180
-
 
181
  btn_separate.click(separate_fn, song_input, [text_output1, vocal_output1,instrumental_output1,vocal_input1,instrumental_input1])
182
  btn_convert.click(convert_fn, [model_name, vocal_input1,micro_input,vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale], [text_output2, vc_output2,vocal_input2])
183
  btn_compose.click(compose_fn,[vocal_input2,instrumental_input1,mixing_ratio],[text_output3,song_output])
184
- btn_reboot.click(reboot)
185
  btn_use_convert.click(lambda x:x,vc_output2,vocal_input2)
186
  btn_use_separate.click(lambda x:x,vocal_output1,vocal_input1)
187
  btn_use_separate2.click(lambda x:x,instrumental_output1,instrumental_input1)
 
13
  import utils
14
  from spleeter import Separator
15
  import time
16
+ from datetime import datetime, timedelta
17
 
18
  build_dir=os.getcwd()
19
  if build_dir == "/home/aistudio":
 
23
 
24
  model_list_path = model_dir + "/model_list.txt"
25
 
26
+ current_time = datetime.now()
27
+ one_hour_later = current_time + timedelta(hours=1)
28
 
29
  # 筛选出文件夹
30
  models = []
 
34
  models.append(os.path.splitext(filename)[0])
35
  cache_model = {}
36
 
37
+ def callback(text):
38
+ if text == "reboot":
39
+ os._exit(0)
 
 
40
  else:
41
+ global start_time
42
+ if time.time() - start_time >= 3600:
43
+ os._exit(0)
44
+ else:
45
+ return text
46
 
47
  def separate_fn(song_input):
48
  try:
 
140
 
141
 
142
  app = gr.Blocks()
143
+
144
  with app:
145
  gr.Markdown('<h1 style="text-align: center;">SVC歌声转换全流程体验(伴奏分离,转换,混音)</h1>')
146
  with gr.Tabs() as tabs:
 
180
  song_output = gr.Audio(label="输出歌曲",interactive=False)
181
 
182
  with gr.TabItem("设置"):
183
+ start_time = time.time()
184
+ output = gr.Textbox(label="输出",placeholder=f"距离下一次允许重启时间为{one_hour_later}")
185
+ btn_reboot = gr.Button(label="重启")
186
  btn_separate.click(separate_fn, song_input, [text_output1, vocal_output1,instrumental_output1,vocal_input1,instrumental_input1])
187
  btn_convert.click(convert_fn, [model_name, vocal_input1,micro_input,vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale], [text_output2, vc_output2,vocal_input2])
188
  btn_compose.click(compose_fn,[vocal_input2,instrumental_input1,mixing_ratio],[text_output3,song_output])
189
+ btn_reboot.click(callback,output)
190
  btn_use_convert.click(lambda x:x,vc_output2,vocal_input2)
191
  btn_use_separate.click(lambda x:x,vocal_output1,vocal_input1)
192
  btn_use_separate2.click(lambda x:x,instrumental_output1,instrumental_input1)