Razoa commited on
Commit
f201b20
·
verified ·
1 Parent(s): a9c4f70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -3,50 +3,45 @@ from pedalboard import Pedalboard, Compressor, Gain, Limiter, HighpassFilter
3
  from pedalboard.io import AudioFile
4
  import os
5
  import tempfile
6
- import shutil
7
 
8
  def master_audio(input_file):
9
  if input_file is None:
10
  return None
11
 
12
  try:
13
- # 1. Mamaky ny rakitra feo (Gradio dia manome path mivantana)
14
  with AudioFile(input_file) as f:
15
  audio = f.read(f.frames)
16
  samplerate = f.samplerate
17
 
18
- # 2. Ny "Chain" an'ny Mastering (Correction HighpassFilter)
19
  board = Pedalboard([
20
  HighpassFilter(cutoff_frequency_hz=30),
21
- Compressor(threshold_db=-16, ratio=2.5),
22
- Gain(gain_db=2),
23
- Limiter(threshold_db=-1.0)
24
  ])
25
 
26
- # 3. Manatanteraka ny Mastering
27
  mastered_audio = board(audio, samplerate)
28
 
29
- # 4. Mitahiry amin'ny toerana azo antoka
30
- output_path = os.path.join(tempfile.gettempdir(), "mastered_output.wav")
31
  with AudioFile(output_path, 'w', samplerate, mastered_audio.shape[0]) as f:
32
  f.write(mastered_audio)
33
 
34
  return output_path
35
  except Exception as e:
36
- print(f"Error: {e}")
37
  return None
38
 
39
- # 5. Interface voadio tsara
40
- with gr.Blocks() as demo:
41
- gr.Markdown("# AI Audio Masterer Pro")
42
- gr.Markdown("Ampidiro ny hira, henoy, ary tsindrio ny Submit mba hanaovana mastering.")
43
-
44
- with gr.Row():
45
- audio_in = gr.Audio(type="filepath", label="Hira tany am-boalohany")
46
- audio_out = gr.Audio(label="Hira efa vita Mastering")
47
-
48
- submit_btn = gr.Button("Submit / Master my Track", variant="primary")
49
- submit_btn.click(fn=master_audio, inputs=audio_in, outputs=audio_out)
50
 
51
  if __name__ == "__main__":
52
- demo.launch()
 
3
  from pedalboard.io import AudioFile
4
  import os
5
  import tempfile
 
6
 
7
  def master_audio(input_file):
8
  if input_file is None:
9
  return None
10
 
11
  try:
12
+ # 1. Mamaky ny rakitra
13
  with AudioFile(input_file) as f:
14
  audio = f.read(f.frames)
15
  samplerate = f.samplerate
16
 
17
+ # 2. Mastering Chain tsotra
18
  board = Pedalboard([
19
  HighpassFilter(cutoff_frequency_hz=30),
20
+ Compressor(threshold_db=-18, ratio=3.0),
21
+ Gain(gain_db=3),
22
+ Limiter(threshold_db=-0.5)
23
  ])
24
 
 
25
  mastered_audio = board(audio, samplerate)
26
 
27
+ # 3. Tehirizina amin'ny anarana mazava
28
+ output_path = os.path.join(tempfile.gettempdir(), "mastered.wav")
29
  with AudioFile(output_path, 'w', samplerate, mastered_audio.shape[0]) as f:
30
  f.write(mastered_audio)
31
 
32
  return output_path
33
  except Exception as e:
 
34
  return None
35
 
36
+ # 4. Interface natao ho an'ny Mobile (tsy misy Blocks be pitsiny)
37
+ demo = gr.Interface(
38
+ fn=master_audio,
39
+ inputs=gr.Audio(type="filepath", label="Hira ampidirina", sources=["upload"]),
40
+ outputs=gr.Audio(label="Hira efa vita"),
41
+ title="AI Master Pro",
42
+ # Ity 'concurrency_limit' ity dia manampy amin'ny fitoniana
43
+ concurrency_limit=5
44
+ )
 
 
45
 
46
  if __name__ == "__main__":
47
+ demo.launch(share=True)