Riko arudianshā commited on
Commit
2afaa21
1 Parent(s): 66716d7

Update app_multi.py

Browse files
Files changed (1) hide show
  1. app_multi.py +66 -2
app_multi.py CHANGED
@@ -74,8 +74,48 @@ app_css = '''
74
  }
75
  '''
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  app = gr.Blocks(
78
- theme=gr.themes.Soft(primary_hue="orange", secondary_hue="slate"),
79
  css=app_css,
80
  analytics_enabled=False
81
  )
@@ -487,7 +527,31 @@ with app:
487
  outputs=[model_info],
488
  show_progress=False,
489
  queue=False
490
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
 
492
  app.queue(
493
  concurrency_count=1,
 
74
  }
75
  '''
76
 
77
+
78
+
79
+ rvc_models_dir = os.path.join(BASE_DIR, 'model')
80
+
81
+
82
+ def download_online_model(url, dir_name, progress=gr.Progress()):
83
+ try:
84
+ progress(0, desc=f'[~] Downloading voice model with name {dir_name}...')
85
+ zip_name = url.split('/')[-1]
86
+ extraction_folder = os.path.join(rvc_models_dir, dir_name)
87
+ if os.path.exists(extraction_folder):
88
+ raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
89
+
90
+ if 'pixeldrain.com' in url:
91
+ url = f'https://pixeldrain.com/api/file/{zip_name}'
92
+
93
+ urllib.request.urlretrieve(url, zip_name)
94
+
95
+ progress(0.5, desc='[~] Extracting zip...')
96
+ extract_zip(extraction_folder, zip_name)
97
+ return f'[+] {dir_name} Model successfully downloaded!'
98
+
99
+ except Exception as e:
100
+ raise gr.Error(str(e))
101
+
102
+
103
+ def upload_local_model(zip_path, dir_name, progress=gr.Progress()):
104
+ try:
105
+ extraction_folder = os.path.join(rvc_models_dir, dir_name)
106
+ if os.path.exists(extraction_folder):
107
+ raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
108
+
109
+ zip_name = zip_path.name
110
+ progress(0.5, desc='[~] Extracting zip...')
111
+ extract_zip(extraction_folder, zip_name)
112
+ return f'[+] {dir_name} Model successfully uploaded!'
113
+
114
+ except Exception as e:
115
+ raise gr.Error(str(e))
116
+
117
  app = gr.Blocks(
118
+ theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="slate"),
119
  css=app_css,
120
  analytics_enabled=False
121
  )
 
527
  outputs=[model_info],
528
  show_progress=False,
529
  queue=False
530
+ ),
531
+ with gr.Tab('Download model'):
532
+
533
+ with gr.Tab('From HuggingFace/Pixeldrain URL'):
534
+ with gr.Row():
535
+ model_zip_link = gr.Text(label='Download link to model', info='Should be a zip file containing a .pth model file and an optional .index file.')
536
+ model_name = gr.Text(label='Name your model', info='Give your new model a unique name from your other voice models.')
537
+
538
+ with gr.Row():
539
+ download_btn = gr.Button('Download 🌐', variant='primary', scale=19)
540
+ dl_output_message = gr.Text(label='Output Message', interactive=False, scale=20)
541
+
542
+ download_btn.click(download_online_model, inputs=[model_zip_link, model_name], outputs=dl_output_message)
543
+
544
+ gr.Markdown('## Input Examples')
545
+ gr.Examples(
546
+ [
547
+ ['https://huggingface.co/phant0m4r/LiSA/resolve/main/LiSA.zip', 'Lisa'],
548
+ ['https://pixeldrain.com/u/3tJmABXA', 'Gura'],
549
+ ['https://huggingface.co/Kit-Lemonfoot/kitlemonfoot_rvc_models/resolve/main/AZKi%20(Hybrid).zip', 'Azki']
550
+ ],
551
+ [model_zip_link, model_name],
552
+ [],
553
+ download_online_model,
554
+ )
555
 
556
  app.queue(
557
  concurrency_count=1,