Blane187 commited on
Commit
ef46557
1 Parent(s): dcf8a83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -39
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
- with wave.open(audio_file, 'rb') as audio:
7
- frames = audio.getnframes()
8
- rate = audio.getframerate()
9
- duration = frames / float(rate)
10
- return duration
 
 
 
 
11
 
12
  def get_training_info(audio_file):
13
- if audio_file is None:
14
- gr.Error('the audio file pls')
15
-
16
- duration = get_audio_duration(audio_file)
17
- sample_rate = wave.open(audio_file, 'rb').getframerate()
18
-
19
- training_info = {
20
- (0, 2): (150, 'TITAN'),
21
- (2, 3): (200, 'TITAN'),
22
- (3, 5): (250, 'TITAN'),
23
- (5, 10): (300, 'normal'),
24
- (10, 25): (500, 'Normal'),
25
- (25, 45): (700, 'Normal'),
26
- (45, 60): (1000, 'Normal')
27
- }
28
-
29
- for (min_duration, max_duration), (epochs, pretrain) in training_info.items():
30
- if min_duration <= duration < max_duration:
31
- break
32
- else:
33
- gr.Info('Duration is not within the specified range.')
34
-
35
- return f'You should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate/1000}kHz** sample rate. Good luck with your training!'
 
 
 
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
- audio_p = gr.Audio(type="filepath", label="Your Audio here")
40
- wtar = gr.Button("Start!")
41
- audio_q = gr.Textbox(scale=3, label="Your Output here")
42
- wtar.click(get_training_info, inputs=[audio_p], outputs=[audio_q])
 
43
  with gr.Tab("Credits"):
44
- gr.Markdown("### This code Originaly by [TheStinger](https://huggingface.co/TheStinger)<br> edit by me (Blane187)")
45
 
46
  with gr.Tab('Tutorial'):
47
  gr.Markdown(
48
  """
49
- Step by Step to use this stuff lol
50
 
51
- 1. Upload audio file (or record yourself by tap mic button)
52
- 2. Click `Start!` button
53
 
54
- And, You Done!
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)