haoheliu commited on
Commit
c2747d4
·
verified ·
1 Parent(s): d8595ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -16,6 +16,7 @@ st.title("AudioSR: Versatile Audio Super-Resolution")
16
  st.write("""
17
  Upload your low-resolution audio files, and AudioSR will enhance them to high fidelity!
18
  Supports all types of audio (music, speech, sound effects, etc.) with arbitrary sampling rates.
 
19
  """)
20
 
21
  # Upload audio file
@@ -49,16 +50,23 @@ if uploaded_file and st.button("Enhance Audio"):
49
  # Create temp directory for saving files
50
  with tempfile.TemporaryDirectory() as tmp_dir:
51
  input_path = os.path.join(tmp_dir, "input.wav")
 
52
  output_path = os.path.join(tmp_dir, "output.wav")
53
 
54
  # Save uploaded file locally
55
  with open(input_path, "wb") as f:
56
  f.write(uploaded_file.read())
57
 
58
- # Plot input spectrogram
59
- st.write("Input Audio Spectrogram:")
60
- input_spectrogram = plot_spectrogram(input_path, title="Input Audio Spectrogram")
61
- st.pyplot(input_spectrogram)
 
 
 
 
 
 
62
 
63
  # Build and load the model
64
  audiosr = build_model(model_name=model_name, device=device)
@@ -66,7 +74,7 @@ if uploaded_file and st.button("Enhance Audio"):
66
  # Perform super-resolution
67
  waveform = super_resolution(
68
  audiosr,
69
- input_path,
70
  seed=random_seed,
71
  guidance_scale=guidance_scale,
72
  ddim_steps=ddim_steps,
@@ -74,7 +82,7 @@ if uploaded_file and st.button("Enhance Audio"):
74
  )
75
 
76
  # Save enhanced audio
77
- save_wave(waveform, inputpath=input_path, savepath=tmp_dir, name="output", samplerate=48000)
78
 
79
  # Plot output spectrogram
80
  st.write("Enhanced Audio Spectrogram:")
@@ -82,8 +90,8 @@ if uploaded_file and st.button("Enhance Audio"):
82
  st.pyplot(output_spectrogram)
83
 
84
  # Display audio players and download link
85
- st.audio(input_path, format="audio/wav")
86
- st.write("Original Audio:")
87
 
88
  st.audio(output_path, format="audio/wav")
89
  st.write("Enhanced Audio:")
 
16
  st.write("""
17
  Upload your low-resolution audio files, and AudioSR will enhance them to high fidelity!
18
  Supports all types of audio (music, speech, sound effects, etc.) with arbitrary sampling rates.
19
+ Only the first 10 seconds of the audio will be processed.
20
  """)
21
 
22
  # Upload audio file
 
50
  # Create temp directory for saving files
51
  with tempfile.TemporaryDirectory() as tmp_dir:
52
  input_path = os.path.join(tmp_dir, "input.wav")
53
+ truncated_path = os.path.join(tmp_dir, "truncated.wav")
54
  output_path = os.path.join(tmp_dir, "output.wav")
55
 
56
  # Save uploaded file locally
57
  with open(input_path, "wb") as f:
58
  f.write(uploaded_file.read())
59
 
60
+ # Load and truncate the first 10 seconds
61
+ y, sr = librosa.load(input_path, sr=None)
62
+ max_samples = sr * 10 # First 10 seconds
63
+ y_truncated = y[:max_samples]
64
+ librosa.output.write_wav(truncated_path, y_truncated, sr)
65
+
66
+ # Plot truncated spectrogram
67
+ st.write("Truncated Input Audio Spectrogram (First 10 seconds):")
68
+ truncated_spectrogram = plot_spectrogram(truncated_path, title="Truncated Input Audio Spectrogram")
69
+ st.pyplot(truncated_spectrogram)
70
 
71
  # Build and load the model
72
  audiosr = build_model(model_name=model_name, device=device)
 
74
  # Perform super-resolution
75
  waveform = super_resolution(
76
  audiosr,
77
+ truncated_path,
78
  seed=random_seed,
79
  guidance_scale=guidance_scale,
80
  ddim_steps=ddim_steps,
 
82
  )
83
 
84
  # Save enhanced audio
85
+ save_wave(waveform, inputpath=truncated_path, savepath=tmp_dir, name="output", samplerate=48000)
86
 
87
  # Plot output spectrogram
88
  st.write("Enhanced Audio Spectrogram:")
 
90
  st.pyplot(output_spectrogram)
91
 
92
  # Display audio players and download link
93
+ st.audio(truncated_path, format="audio/wav")
94
+ st.write("Truncated Original Audio (First 10 seconds):")
95
 
96
  st.audio(output_path, format="audio/wav")
97
  st.write("Enhanced Audio:")