Hev832 commited on
Commit
7e68f03
·
verified ·
1 Parent(s): 73c0d5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -19
app.py CHANGED
@@ -27,27 +27,30 @@ main_dir = Path().resolve()
27
  print(main_dir)
28
 
29
  os.chdir(main_dir)
30
- models_dir = "rvc_models"
31
  audio_separat_dir = main_dir / "audio_input"
32
 
33
- rvc_models_dir = os.path.join(models_dir)
34
-
35
  AUDIO_DIR = main_dir / 'audio_input'
36
 
37
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
 
41
- def get_current_models(models_dir):
42
- models_list = os.listdir(models_dir)
43
- items_to_remove = ['hubert_base.pt', 'readme.txt', 'rmvpe.pt']
44
- return [item for item in models_list if item not in items_to_remove]
45
 
46
 
47
 
48
  # Function to get the list of audio files in the specified directory
49
  def get_audio_files():
50
- if not os.path.exists(AUDIO_DIR):
51
  os.makedirs(AUDIO_DIR)
52
  # List all supported audio file formats
53
  return [f for f in os.listdir(AUDIO_DIR) if f.lower().endswith(('.mp3', '.wav', '.flac', '.ogg', '.aac'))]
@@ -70,13 +73,6 @@ def play_audio(file_path):
70
 
71
 
72
 
73
- def update_models_list():
74
- models_l = get_current_models(rvc_models_dir)
75
- dropdown_instance = gr.Dropdown(choices=models_l)
76
- return dropdown_instance
77
-
78
-
79
- voice_models = get_current_models(rvc_models_dir)
80
 
81
 
82
  def download_audio(url):
@@ -261,8 +257,16 @@ with gr.Blocks(title="Hex RVC", theme=gr.themes.Default(primary_hue="red", secon
261
  gr.Markdown(" join [AIHub](https://discord.gg/aihub) to get the rvc model!")
262
 
263
  with gr.Tab("Inference"):
264
- MODEL_NAME = gr.Dropdown(voice_models, label='Voice Models', info='Models folder "AICoverGen --> rvc_models". After new models are added into this folder, click the refresh button')
265
- ref_btn = gr.Button('Refresh Models 🔁', variant='primary')
 
 
 
 
 
 
 
 
266
  with gr.Row():
267
  # = gr.Textbox(label="Model Name", placeholder="Enter model name")
268
  # SOUND_PATH = gr.Textbox(label="Audio Path (Optional)", placeholder="Leave blank to upload audio")
@@ -327,9 +331,12 @@ with gr.Blocks(title="Hex RVC", theme=gr.themes.Default(primary_hue="red", secon
327
  )
328
 
329
  with gr.Tab("Download RVC Model"):
330
- url = gr.Textbox(label="Your model URL")
331
- dirname = gr.Textbox(label="Your Model name")
 
 
332
  button_model = gr.Button("Download model")
 
333
  button_model.click(fn=download_online_model, inputs=[url, dirname], outputs=[dirname])
334
  with gr.Tab("Audio Separation"):
335
  with gr.Row():
 
27
  print(main_dir)
28
 
29
  os.chdir(main_dir)
30
+ models_dir = main_dir / "rvc_models"
31
  audio_separat_dir = main_dir / "audio_input"
32
 
 
 
33
  AUDIO_DIR = main_dir / 'audio_input'
34
 
35
 
36
+ # Function to list all folders in the models directory
37
+ def get_folders():
38
+ if models_dir.exists() and models_dir.is_dir():
39
+ return [folder.name for folder in models_dir.iterdir() if folder.is_dir()]
40
+ return []
41
+
42
+ # Function to refresh and return the list of folders
43
+ def refresh_folders():
44
+ return gr.Dropdown.update(choices=get_folders())
45
 
46
 
47
 
 
 
 
 
48
 
49
 
50
 
51
  # Function to get the list of audio files in the specified directory
52
  def get_audio_files():
53
+ if not os.path.exists(QUDIO_DIR):
54
  os.makedirs(AUDIO_DIR)
55
  # List all supported audio file formats
56
  return [f for f in os.listdir(AUDIO_DIR) if f.lower().endswith(('.mp3', '.wav', '.flac', '.ogg', '.aac'))]
 
73
 
74
 
75
 
 
 
 
 
 
 
 
76
 
77
 
78
  def download_audio(url):
 
257
  gr.Markdown(" join [AIHub](https://discord.gg/aihub) to get the rvc model!")
258
 
259
  with gr.Tab("Inference"):
260
+ MODEL_NAME = gr.Dropdown(
261
+ label="Select a Model Folder",
262
+ choices=get_folders(),
263
+ interactive=True,
264
+ elem_id="model_folder"
265
+ )
266
+ # Button to refresh the list of folders
267
+ refresh_button = gr.Button("Refresh Folder List")
268
+ # Action to refresh folder list on button click
269
+ refresh_button.click(refresh_folders, outputs=folder_dropdown)
270
  with gr.Row():
271
  # = gr.Textbox(label="Model Name", placeholder="Enter model name")
272
  # SOUND_PATH = gr.Textbox(label="Audio Path (Optional)", placeholder="Leave blank to upload audio")
 
331
  )
332
 
333
  with gr.Tab("Download RVC Model"):
334
+ with gr.Row():
335
+ url = gr.Textbox(label="Your model URL")
336
+ dirname = gr.Textbox(label="Your Model name")
337
+ outout_pah = gr.Textbox(label="output download", interactive=False)
338
  button_model = gr.Button("Download model")
339
+
340
  button_model.click(fn=download_online_model, inputs=[url, dirname], outputs=[dirname])
341
  with gr.Tab("Audio Separation"):
342
  with gr.Row():