Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,58 +1,65 @@
|
|
1 |
import wave
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
def get_audio_duration(audio_file):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def get_training_info(audio_file):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
with gr.Blocks(theme=gr.themes.Base(primary_hue="sky", secondary_hue="blue"), title="RVC TRAINING HELPER") as demo:
|
38 |
with gr.Tab("Main Settings"):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
with gr.Tab("Credits"):
|
44 |
-
gr.Markdown("### This code
|
45 |
|
46 |
with gr.Tab('Tutorial'):
|
47 |
gr.Markdown(
|
48 |
"""
|
49 |
-
Step by Step
|
50 |
|
51 |
-
1. Upload audio file (or record yourself by
|
52 |
-
2. Click `Start!` button
|
53 |
|
54 |
-
And
|
55 |
"""
|
56 |
)
|
57 |
-
|
58 |
demo.launch(debug=True)
|
|
|
1 |
import wave
|
2 |
import gradio as gr
|
3 |
|
|
|
4 |
def get_audio_duration(audio_file):
|
5 |
+
"""Get the duration of the audio file in seconds."""
|
6 |
+
try:
|
7 |
+
with wave.open(audio_file, 'rb') as audio:
|
8 |
+
frames = audio.getnframes()
|
9 |
+
rate = audio.getframerate()
|
10 |
+
duration = frames / float(rate)
|
11 |
+
return duration
|
12 |
+
except wave.Error:
|
13 |
+
raise ValueError("Invalid audio file. Please upload a valid .wav file.")
|
14 |
|
15 |
def get_training_info(audio_file):
|
16 |
+
"""Determine training parameters based on the duration of the audio file."""
|
17 |
+
try:
|
18 |
+
if audio_file is None:
|
19 |
+
raise ValueError as e:
|
20 |
+
return gr.Error('Please provide an audio file.')
|
21 |
+
|
22 |
+
duration = get_audio_duration(audio_file)
|
23 |
+
sample_rate = wave.open(audio_file, 'rb').getframerate()
|
24 |
+
|
25 |
+
training_info = {
|
26 |
+
(0, 2): (150, 'TITAN'),
|
27 |
+
(2, 3): (200, 'TITAN'),
|
28 |
+
(3, 5): (250, 'TITAN'),
|
29 |
+
(5, 10): (300, 'normal'),
|
30 |
+
(10, 25): (500, 'Normal'),
|
31 |
+
(25, 45): (700, 'Normal'),
|
32 |
+
(45, 60): (1000, 'Normal')
|
33 |
+
}
|
34 |
+
|
35 |
+
for (min_duration, max_duration), (epochs, pretrain) in training_info.items():
|
36 |
+
if min_duration <= duration < max_duration:
|
37 |
+
return f'You should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate / 1000} kHz** sample rate. Good luck with your training!'
|
38 |
+
|
39 |
+
return 'Duration is not within the specified range.'
|
40 |
+
except ValueError as e:
|
41 |
+
return gr.Error(str(e))
|
42 |
|
43 |
with gr.Blocks(theme=gr.themes.Base(primary_hue="sky", secondary_hue="blue"), title="RVC TRAINING HELPER") as demo:
|
44 |
with gr.Tab("Main Settings"):
|
45 |
+
audio_input = gr.Audio(type="filepath", label="Your Audio here")
|
46 |
+
start_button = gr.Button("Start!")
|
47 |
+
output_text = gr.Textbox(scale=3, label="Your Output here")
|
48 |
+
start_button.click(get_training_info, inputs=[audio_input], outputs=[output_text])
|
49 |
+
|
50 |
with gr.Tab("Credits"):
|
51 |
+
gr.Markdown("### This code originally by [TheStinger](https://huggingface.co/TheStinger)<br>Edited by Blane187")
|
52 |
|
53 |
with gr.Tab('Tutorial'):
|
54 |
gr.Markdown(
|
55 |
"""
|
56 |
+
### Step by Step Guide
|
57 |
|
58 |
+
1. Upload an audio file (or record yourself by tapping the mic button).
|
59 |
+
2. Click the `Start!` button.
|
60 |
|
61 |
+
And you're done!
|
62 |
"""
|
63 |
)
|
64 |
+
|
65 |
demo.launch(debug=True)
|