Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,28 +9,32 @@ os.environ['weight_root']="assets/weights"
|
|
9 |
from infer.modules.vc.modules import VC
|
10 |
from configs.config import Config
|
11 |
import torch
|
12 |
-
|
13 |
config = Config()
|
14 |
vc = VC(config)
|
15 |
|
|
|
|
|
|
|
|
|
16 |
def load_model(model_picker,index_picker):
|
17 |
logs = show_available("logs")
|
18 |
if model_picker.replace(".pth","") in logs:
|
19 |
log = model_picker.replace(".pth","")
|
20 |
else:
|
21 |
log = index_picker
|
22 |
-
|
23 |
vc.get_vc(model_picker,0,0)
|
24 |
return {"choices":logs,"value":log,"__type__": "update"}
|
25 |
|
26 |
def convert(audio_picker,model_picker,index_picker,index_rate,pitch,method):
|
27 |
-
|
28 |
now = datetime.now().strftime("%d%m%Y%H%M%S")
|
29 |
index_files = glob.glob(f"logs/{index_picker}/*.index")
|
30 |
if index_files:
|
31 |
print(f"Found index: {index_files[0]}")
|
32 |
else:
|
33 |
-
|
34 |
print("Did not find a matching .index file")
|
35 |
index_files = [f'logs/{model_picker}/fake_index.index']
|
36 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -226,7 +230,7 @@ def upload_file(file):
|
|
226 |
os.remove(f'audios/{filename}')
|
227 |
shutil.move(file_path,'audios')
|
228 |
else:
|
229 |
-
|
230 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
231 |
|
232 |
def refresh():
|
@@ -271,9 +275,15 @@ with gr.Blocks() as app:
|
|
271 |
with gr.TabItem("2.Choose an audio file:"):
|
272 |
recorder = gr.Microphone(label="Record audio here...",type='filepath')
|
273 |
audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
|
274 |
-
|
|
|
|
|
|
|
275 |
with gr.TabItem("(Or upload a new file here)"):
|
276 |
-
|
|
|
|
|
|
|
277 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
278 |
audio_refresher = gr.Button("Refresh")
|
279 |
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
|
@@ -284,4 +294,4 @@ with gr.Blocks() as app:
|
|
284 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
285 |
convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
|
286 |
|
287 |
-
app.queue(max_size=20).launch(debug=True)
|
|
|
9 |
from infer.modules.vc.modules import VC
|
10 |
from configs.config import Config
|
11 |
import torch
|
12 |
+
os.makedirs(os.path.join(".", "audios"), exist_ok=True)
|
13 |
config = Config()
|
14 |
vc = VC(config)
|
15 |
|
16 |
+
def warn(text):
|
17 |
+
try: gr.Warning(text)
|
18 |
+
except: pass
|
19 |
+
|
20 |
def load_model(model_picker,index_picker):
|
21 |
logs = show_available("logs")
|
22 |
if model_picker.replace(".pth","") in logs:
|
23 |
log = model_picker.replace(".pth","")
|
24 |
else:
|
25 |
log = index_picker
|
26 |
+
warn("Could not find a matching index file.")
|
27 |
vc.get_vc(model_picker,0,0)
|
28 |
return {"choices":logs,"value":log,"__type__": "update"}
|
29 |
|
30 |
def convert(audio_picker,model_picker,index_picker,index_rate,pitch,method):
|
31 |
+
warn("Your audio is being converted. Please wait.")
|
32 |
now = datetime.now().strftime("%d%m%Y%H%M%S")
|
33 |
index_files = glob.glob(f"logs/{index_picker}/*.index")
|
34 |
if index_files:
|
35 |
print(f"Found index: {index_files[0]}")
|
36 |
else:
|
37 |
+
warn("Sorry, I couldn't find your .index file.")
|
38 |
print("Did not find a matching .index file")
|
39 |
index_files = [f'logs/{model_picker}/fake_index.index']
|
40 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
230 |
os.remove(f'audios/{filename}')
|
231 |
shutil.move(file_path,'audios')
|
232 |
else:
|
233 |
+
warn('File incompatible')
|
234 |
return {"choices":show_available('audios'),"__type__": "update","value":filename}
|
235 |
|
236 |
def refresh():
|
|
|
275 |
with gr.TabItem("2.Choose an audio file:"):
|
276 |
recorder = gr.Microphone(label="Record audio here...",type='filepath')
|
277 |
audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
|
278 |
+
try:
|
279 |
+
recorder.stop_recording(upload_file, inputs=[recorder],outputs=[audio_picker])
|
280 |
+
except:
|
281 |
+
recorder.upload(upload_file, inputs=[recorder],outputs=[audio_picker])
|
282 |
with gr.TabItem("(Or upload a new file here)"):
|
283 |
+
try:
|
284 |
+
dropbox = gr.File(label="Drop an audio here.",file_types=['.wav', '.mp3', '.ogg', '.flac', '.aac'], type="filepath")
|
285 |
+
except:#Version Compatibiliy
|
286 |
+
dropbox = gr.File(label="Drop an audio here.",file_types=['.wav', '.mp3', '.ogg', '.flac', '.aac'], type="file")
|
287 |
dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
|
288 |
audio_refresher = gr.Button("Refresh")
|
289 |
audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker,index_picker])
|
|
|
294 |
audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
|
295 |
convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
|
296 |
|
297 |
+
app.queue(max_size=20).launch(debug=True,share=True)
|