PatienceIzere commited on
Commit
4cd9b29
Β·
verified Β·
1 Parent(s): b2a0161

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -37
app.py CHANGED
@@ -135,52 +135,54 @@ def main():
135
  audio_file = st.session_state.last_recorded_audio
136
 
137
  if st.button("🎡 Transcribe Audio"):
138
- with st.spinner("Transcribing audio..."):
139
- try:
140
  # Initialize the transcriber
141
  if use_hf:
142
  transcriber = HFTranscriber(model_name=model_name)
143
  else:
144
  transcriber = AudioTranscriber()
145
 
146
- # Create output directory
147
- os.makedirs("outputs", exist_ok=True)
148
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
149
- midi_output = os.path.join("outputs", f"output_{timestamp}.mid")
150
- musicxml_output = os.path.join("outputs", f"output_{timestamp}.musicxml")
151
- # Transcribe
152
- transcriber.transcribe(audio_file, midi_output, musicxml_output)
153
-
154
- # Show success message
155
- st.success("🎡 Transcription completed successfully!")
156
-
157
- # Show download links
158
- st.markdown("### Download Results")
159
-
160
- # Display MIDI file
161
- if os.path.exists(midi_output):
162
- st.markdown(f"**MIDI File:** {get_binary_file_downloader_html(midi_output, 'Download MIDI')}",
163
- unsafe_allow_html=True)
164
-
165
- # Display MusicXML file
166
- if os.path.exists(musicxml_output):
167
- st.markdown(f"**MusicXML File:** {get_binary_file_downloader_html(musicxml_output, 'Download MusicXML')}",
168
- unsafe_allow_html=True)
169
-
170
- # Display a preview of the transcription if possible
171
  try:
172
- from IPython.display import display, Audio
173
- audio = Audio(audio_file)
174
- st.audio(audio_file, format='audio/wav')
175
- except Exception as e:
176
- st.warning(f"Could not display audio preview: {str(e)}")
177
 
178
- except Exception as e:
179
- st.error(f"❌ Error during transcription: {str(e)}")
180
- st.exception(e) # Show full traceback for debugging
181
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  except Exception as e:
183
- st.error(f"An error occurred during transcription: {str(e)}")
184
  st.exception(e) # Show full traceback for debugging
185
 
186
  # Clean up temporary files
 
135
  audio_file = st.session_state.last_recorded_audio
136
 
137
  if st.button("🎡 Transcribe Audio"):
138
+ try:
139
+ with st.spinner("Transcribing audio..."):
140
  # Initialize the transcriber
141
  if use_hf:
142
  transcriber = HFTranscriber(model_name=model_name)
143
  else:
144
  transcriber = AudioTranscriber()
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  try:
147
+ # Create output directory
148
+ os.makedirs("outputs", exist_ok=True)
149
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
150
+ midi_output = os.path.join("outputs", f"output_{timestamp}.mid")
151
+ musicxml_output = os.path.join("outputs", f"output_{timestamp}.musicxml")
152
 
153
+ # Transcribe
154
+ transcriber.transcribe(audio_file, midi_output, musicxml_output)
155
+
156
+ # Show success message
157
+ st.success("🎡 Transcription completed successfully!")
158
+
159
+ # Show download links
160
+ st.markdown("### Download Results")
161
+
162
+ # Display MIDI file
163
+ if os.path.exists(midi_output):
164
+ st.markdown(f"**MIDI File:** {get_binary_file_downloader_html(midi_output, 'Download MIDI')}",
165
+ unsafe_allow_html=True)
166
+
167
+ # Display MusicXML file
168
+ if os.path.exists(musicxml_output):
169
+ st.markdown(f"**MusicXML File:** {get_binary_file_downloader_html(musicxml_output, 'Download MusicXML')}",
170
+ unsafe_allow_html=True)
171
+
172
+ # Display a preview of the transcription if possible
173
+ try:
174
+ from IPython.display import display, Audio
175
+ audio = Audio(audio_file)
176
+ st.audio(audio_file, format='audio/wav')
177
+ except Exception as e:
178
+ st.warning(f"Could not display audio preview: {str(e)}")
179
+
180
+ except Exception as e:
181
+ st.error(f"❌ Error during transcription: {str(e)}")
182
+ st.exception(e) # Show full traceback for debugging
183
+
184
  except Exception as e:
185
+ st.error(f"An error occurred during transcription setup: {str(e)}")
186
  st.exception(e) # Show full traceback for debugging
187
 
188
  # Clean up temporary files