Blane187 commited on
Commit
d052f09
1 Parent(s): e6cf086

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -40,9 +40,17 @@ pretrains = {
40
  }
41
  }
42
 
 
 
 
 
 
 
 
43
  def get_training_info(audio_file):
44
  if audio_file is None:
45
  return 'Please provide an audio file!'
 
46
  duration = get_audio_duration(audio_file)
47
  sample_rate = wave.open(audio_file, 'rb').getframerate()
48
 
@@ -60,17 +68,14 @@ def get_training_info(audio_file):
60
  if min_duration <= duration < max_duration:
61
  break
62
  else:
63
- return 'Duration is not within the specified range dude'
64
-
65
- return f'u should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate/1000}khz** sample rate\n good luck at training ;).'
66
-
67
 
 
68
 
69
  with gr.Blocks() as demo:
70
- audio_p = gr.Audio(label="Your Audio here")
71
- audio_q = Textbox(label="Your Output here")
72
  wtar = gr.Button("Start!")
73
  wtar.click(get_training_info, inputs=[audio_p], outputs=[audio_q])
74
 
75
-
76
- demo.launch(debug=True)
 
40
  }
41
  }
42
 
43
+ def get_audio_duration(audio_file):
44
+ with wave.open(audio_file, 'rb') as audio:
45
+ frames = audio.getnframes()
46
+ rate = audio.getframerate()
47
+ duration = frames / float(rate)
48
+ return duration
49
+
50
  def get_training_info(audio_file):
51
  if audio_file is None:
52
  return 'Please provide an audio file!'
53
+
54
  duration = get_audio_duration(audio_file)
55
  sample_rate = wave.open(audio_file, 'rb').getframerate()
56
 
 
68
  if min_duration <= duration < max_duration:
69
  break
70
  else:
71
+ return 'Duration is not within the specified range.'
 
 
 
72
 
73
+ return f'You should use the **{pretrain}** pretrain with **{epochs}** epochs at **{sample_rate/1000}kHz** sample rate. Good luck with your training!'
74
 
75
  with gr.Blocks() as demo:
76
+ audio_p = gr.Audio(source="upload", type="filepath", label="Your Audio here")
77
+ audio_q = gr.Textbox(label="Your Output here")
78
  wtar = gr.Button("Start!")
79
  wtar.click(get_training_info, inputs=[audio_p], outputs=[audio_q])
80
 
81
+ demo.launch(debug=True)