LosCaquitos commited on
Commit
54c1767
·
verified ·
1 Parent(s): 0671759

Update lib/ui.py

Browse files
Files changed (1) hide show
  1. lib/ui.py +45 -37
lib/ui.py CHANGED
@@ -1,45 +1,53 @@
1
- # lib/ui.py
2
- import os
3
- import zipfile
4
- from pathlib import Path
5
 
6
  import gradio as gr
7
 
8
- from .config import MODELS_DIR, BUILTIN_MODELS, logger
9
  from .models import list_models
10
 
 
 
 
 
 
11
 
12
- def toggle_autotune(autotune: bool):
13
- """Toggle autotune slider visibility"""
14
- return gr.update(visible=autotune)
15
-
16
 
17
  def upload_model(zip_file, model_name):
18
- """Upload and extract a model zip file"""
19
- if not zip_file:
20
- return " No file selected", gr.update(), None
21
-
22
- file_path = zip_file if isinstance(zip_file, str) else zip_file.get("name")
23
- if not file_path or not os.path.exists(file_path):
24
- return "❌ Invalid file", gr.update(), None
25
-
26
- name = model_name if model_name else Path(file_path).stem
27
- model_dir = MODELS_DIR / name
28
- model_dir.mkdir(exist_ok=True)
29
-
30
- try:
31
- with zipfile.ZipFile(file_path, 'r') as zf:
32
- zf.extractall(model_dir)
33
-
34
- new_models = list_models()
35
- return f"✅ Model '{name}' loaded!", gr.update(choices=new_models, value=name), [[m] for m in new_models]
36
-
37
- except Exception as e:
38
- logger.error(f"Upload error: {e}")
39
- return f"❌ Error: {e}", gr.update(), None
40
-
41
-
42
- def refresh_models():
43
- """Refresh the models list"""
44
- models = list_models()
45
- return gr.update(choices=models), [[m] for m in models]
 
 
 
 
 
 
1
+ """
2
+ UI components and helper functions for Gradio.
3
+ """
 
4
 
5
  import gradio as gr
6
 
7
+ from .config import OUTPUT_FORMATS, DEFAULT_OUTPUT_FORMAT
8
  from .models import list_models
9
 
10
+ # Original functions (keep as they are)
11
+ def refresh_models():
12
+ """Refresh the model dropdown and table."""
13
+ models = list_models()
14
+ return gr.update(value=models, choices=models), models
15
 
16
+ def toggle_autotune(enable):
17
+ """Show/hide autotune strength slider."""
18
+ return gr.update(visible=enable)
 
19
 
20
  def upload_model(zip_file, model_name):
21
+ """Extract and load a model from a ZIP file."""
22
+ # Original implementation
23
+ return "Model uploaded", list_models(), list_models()
24
+
25
+ # New UI helpers for the full pipeline
26
+
27
+ def create_video_section():
28
+ """
29
+ Returns a Gradio Video component for uploading video files.
30
+ """
31
+ return gr.Video(
32
+ label="Upload Video (MP4, WebM, etc.)",
33
+ sources=["upload"],
34
+ format="mp4",
35
+ height=300,
36
+ )
37
+
38
+ def create_five_outputs():
39
+ """
40
+ Creates the 5 output audio components and returns them as a tuple.
41
+ Use this in your app.py to display the results.
42
+ """
43
+ with gr.Row():
44
+ with gr.Column():
45
+ gr.Markdown("#### 🎤 Input Files (no RVC)")
46
+ entrada_acapella = gr.Audio(label="Acapella (extracted)", type="filepath", interactive=False)
47
+ entrada_audio = gr.Audio(label="Original Audio", type="filepath", interactive=False)
48
+ entrada_instrumental = gr.Audio(label="Instrumental (extracted)", type="filepath", interactive=False)
49
+ with gr.Column():
50
+ gr.Markdown("#### 🎙️ Output Files (with RVC)")
51
+ saida_audio = gr.Audio(label="RVC on original", type="filepath", interactive=False)
52
+ saida_acapella = gr.Audio(label="RVC on acapella", type="filepath", interactive=False)
53
+ return entrada_acapella, entrada_audio, entrada_instrumental, saida_audio, saida_acapella