ahk-d commited on
Commit
5f48921
·
verified ·
1 Parent(s): a3f80ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -7
app.py CHANGED
@@ -1,8 +1,57 @@
1
- """## Gradio Interface for Custom Audio Upload"""
2
-
3
- import gradio as gr
4
- import requests
5
  import tempfile
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # Preset audio URLs
8
  INPUT_ROOT = 'https://adasp.telecom-paris.fr/rc-ext/demos_companion-pages/vqvae_examples/'
@@ -137,7 +186,7 @@ with gr.Blocks(title="VQ-VAE Timbre Transfer", theme=gr.themes.Soft()) as demo:
137
 
138
  Transfer the timbre (tone/texture) from one audio source to another while preserving the musical content.
139
 
140
- **Content**: Musical notes/melody that will be preserved
141
  **Style**: Instrument timbre/texture that will be applied
142
 
143
  ### How It Works:
@@ -230,5 +279,16 @@ with gr.Blocks(title="VQ-VAE Timbre Transfer", theme=gr.themes.Soft()) as demo:
230
  outputs=[output_audio, status_msg]
231
  )
232
 
233
- # Launch
234
- demo.launch(share=True, debug=True, height=1400)
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
 
 
 
2
  import tempfile
3
+ import requests
4
+ import gradio as gr
5
+ import torch
6
+ import librosa
7
+ import numpy as np
8
+ import subprocess
9
+ import sys
10
+
11
+ def install_dependencies():
12
+ """Install required packages for deployment"""
13
+ try:
14
+ if not os.path.exists('ss-vq-vae'):
15
+ print("Cloning ss-vq-vae repository...")
16
+ subprocess.run(['git', 'clone', 'https://github.com/cifkao/ss-vq-vae.git'], check=True)
17
+
18
+ subprocess.run([sys.executable, '-m', 'pip', 'install', './ss-vq-vae/src'], check=True)
19
+ print("Dependencies installed successfully!")
20
+
21
+ except Exception as e:
22
+ print(f"Error installing dependencies: {e}")
23
+ raise
24
+
25
+ # Install dependencies for deployment
26
+ try:
27
+ install_dependencies()
28
+ import confugue
29
+ from ss_vq_vae.models.vqvae_oneshot import Experiment
30
+ except ImportError:
31
+ print("ss-vq-vae not found. Please install manually or run in Colab.")
32
+ sys.exit(1)
33
+
34
+ def download_model():
35
+ """Download model files if they don't exist"""
36
+ model_dir = 'ss-vq-vae/experiments/model'
37
+ os.makedirs(model_dir, exist_ok=True)
38
+
39
+ model_path = os.path.join(model_dir, 'model_state.pt')
40
+ if not os.path.exists(model_path):
41
+ print("Downloading model...")
42
+ url = 'https://adasp.telecom-paris.fr/rc-ext/demos_companion-pages/vqvae_examples/ssvqvae_model_state.pt'
43
+ response = requests.get(url)
44
+ with open(model_path, 'wb') as f:
45
+ f.write(response.content)
46
+ print("Model downloaded successfully!")
47
+
48
+ # Initialize model
49
+ download_model()
50
+ logdir = 'ss-vq-vae/experiments/model'
51
+ cfg = confugue.Configuration.from_yaml_file(os.path.join(logdir, 'config.yaml'))
52
+ exp = cfg.configure(Experiment, logdir=logdir, device='cpu')
53
+ exp.model.load_state_dict(torch.load(os.path.join(logdir, 'model_state.pt'), map_location=exp.device))
54
+ exp.model.train(False)
55
 
56
  # Preset audio URLs
57
  INPUT_ROOT = 'https://adasp.telecom-paris.fr/rc-ext/demos_companion-pages/vqvae_examples/'
 
186
 
187
  Transfer the timbre (tone/texture) from one audio source to another while preserving the musical content.
188
 
189
+ **Content**: Musical notes/melody that will be preserved
190
  **Style**: Instrument timbre/texture that will be applied
191
 
192
  ### How It Works:
 
279
  outputs=[output_audio, status_msg]
280
  )
281
 
282
+ gr.Markdown("""
283
+ ### 🔧 Troubleshooting
284
+ - **Poor transfer quality?** Try different instrument combinations or adjust max duration
285
+ - **Audio doesn't load?** Check internet connection or try different presets
286
+ - **Processing slow?** Reduce max duration or try shorter audio clips
287
+
288
+ ### 📖 Citation
289
+ Original work by Ondřej Cífka (InterDigital R&D and Télécom Paris, 2020).
290
+ Demo by Ali Dulaimi.
291
+ """)
292
+
293
+ if __name__ == "__main__":
294
+ demo.launch(share=True, debug=True, height=1400)