Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,6 +122,8 @@ def main():
|
|
| 122 |
|
| 123 |
# Keep the audio_file in session state for transcription
|
| 124 |
st.session_state.last_recorded_audio = audio_file
|
|
|
|
|
|
|
| 125 |
except Exception as e:
|
| 126 |
st.error(f"Error stopping recording: {str(e)}")
|
| 127 |
finally:
|
|
@@ -129,13 +131,16 @@ def main():
|
|
| 129 |
st.rerun()
|
| 130 |
|
| 131 |
# Transcription Section
|
| 132 |
-
if
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# Create output directory
|
| 141 |
os.makedirs("outputs", exist_ok=True)
|
|
@@ -143,18 +148,37 @@ def main():
|
|
| 143 |
midi_output = os.path.join("outputs", f"output_{timestamp}.mid")
|
| 144 |
musicxml_output = os.path.join("outputs", f"output_{timestamp}.musicxml")
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
except Exception as e:
|
| 160 |
st.error(f"An error occurred during transcription: {str(e)}")
|
|
|
|
| 122 |
|
| 123 |
# Keep the audio_file in session state for transcription
|
| 124 |
st.session_state.last_recorded_audio = audio_file
|
| 125 |
+
# Force a rerun to update the UI
|
| 126 |
+
st.rerun()
|
| 127 |
except Exception as e:
|
| 128 |
st.error(f"Error stopping recording: {str(e)}")
|
| 129 |
finally:
|
|
|
|
| 131 |
st.rerun()
|
| 132 |
|
| 133 |
# Transcription Section
|
| 134 |
+
if 'last_recorded_audio' in st.session_state and st.session_state.last_recorded_audio:
|
| 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 |
+
if use_hf:
|
| 141 |
+
transcriber = HFTranscriber(model_name=model_name)
|
| 142 |
+
else:
|
| 143 |
+
transcriber = AudioTranscriber()
|
| 144 |
|
| 145 |
# Create output directory
|
| 146 |
os.makedirs("outputs", exist_ok=True)
|
|
|
|
| 148 |
midi_output = os.path.join("outputs", f"output_{timestamp}.mid")
|
| 149 |
musicxml_output = os.path.join("outputs", f"output_{timestamp}.musicxml")
|
| 150 |
|
| 151 |
+
try:
|
| 152 |
+
# Transcribe
|
| 153 |
+
transcriber.transcribe(audio_file, midi_output, musicxml_output)
|
| 154 |
+
|
| 155 |
+
# Show success message
|
| 156 |
+
st.success("🎵 Transcription completed successfully!")
|
| 157 |
+
|
| 158 |
+
# Show download links
|
| 159 |
+
st.markdown("### Download Results")
|
| 160 |
+
|
| 161 |
+
# Display MIDI file
|
| 162 |
+
if os.path.exists(midi_output):
|
| 163 |
+
st.markdown(f"**MIDI File:** {get_binary_file_downloader_html(midi_output, 'Download MIDI')}",
|
| 164 |
+
unsafe_allow_html=True)
|
| 165 |
+
|
| 166 |
+
# Display MusicXML file
|
| 167 |
+
if os.path.exists(musicxml_output):
|
| 168 |
+
st.markdown(f"**MusicXML File:** {get_binary_file_downloader_html(musicxml_output, 'Download MusicXML')}",
|
| 169 |
+
unsafe_allow_html=True)
|
| 170 |
+
|
| 171 |
+
# Display a preview of the transcription if possible
|
| 172 |
+
try:
|
| 173 |
+
from IPython.display import display, Audio
|
| 174 |
+
audio = Audio(audio_file)
|
| 175 |
+
st.audio(audio_file, format='audio/wav')
|
| 176 |
+
except Exception as e:
|
| 177 |
+
st.warning(f"Could not display audio preview: {str(e)}")
|
| 178 |
+
|
| 179 |
+
except Exception as e:
|
| 180 |
+
st.error(f"❌ Error during transcription: {str(e)}")
|
| 181 |
+
st.exception(e) # Show full traceback for debugging
|
| 182 |
|
| 183 |
except Exception as e:
|
| 184 |
st.error(f"An error occurred during transcription: {str(e)}")
|