Raaniel commited on
Commit
e34b8a2
·
1 Parent(s): 8e9d377

Upload app.py.py

Browse files
Files changed (1) hide show
  1. app.py.py +41 -0
app.py.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import os
3
+ #os.system('pip install git+https://github.com/peterwilli/audio-maister.git')
4
+ import gradio as gr
5
+
6
+ from audiomaister import VoiceFixer
7
+ from audiomaister.models.gs_audiomaister import AudioMaister
8
+
9
+ USE_CUDA = torch.cuda.is_available()
10
+
11
+ def load_default_weights():
12
+ from huggingface_hub import hf_hub_download
13
+ from pathlib import Path
14
+
15
+ REPO_ID = "peterwilli/audio-maister"
16
+ print(f"Loading standard model weight at {REPO_ID}")
17
+ MODEL_FILE_NAME = "audiomaister_v1.ckpt"
18
+ checkpoint_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILE_NAME)
19
+ return checkpoint_path
20
+
21
+ def inference(input_file, **kwargs):
22
+ checkpoint = load_default_weights()
23
+ state = torch.load(checkpoint)
24
+
25
+ main_model = VoiceFixer(state['hparams'], 1, 'vocals')
26
+ main_model.load_state_dict(state['weights'])
27
+
28
+ inference_model = AudioMaister(main_model)
29
+ inference_model.restore(input=input_file, output="out.wav", mode=0)
30
+
31
+ if USE_CUDA:
32
+ main_model.to('cuda')
33
+ inference_model.to('cuda')
34
+
35
+ return "out.wav"
36
+
37
+ gr.Interface(
38
+ fn=inference,
39
+ inputs=gr.Audio(type="filepath", source="upload"),
40
+ outputs="audio"
41
+ ).launch(debug=True)