Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,14 @@ import io
|
|
| 9 |
import glob
|
| 10 |
import shutil
|
| 11 |
import time
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Configuration dictionary to store app settings
|
| 14 |
app_config = {
|
| 15 |
'RECORDING_ENABLED': False,
|
| 16 |
-
'AUDIO_DEVICES': []
|
|
|
|
| 17 |
}
|
| 18 |
|
| 19 |
def init_recording():
|
|
@@ -318,33 +321,59 @@ def main():
|
|
| 318 |
if 'last_recorded_audio' in st.session_state and st.session_state.last_recorded_audio:
|
| 319 |
audio_file = st.session_state.last_recorded_audio
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
if st.button("🎵 Transcribe Audio"):
|
| 322 |
try:
|
| 323 |
with st.spinner("Transcribing audio..."):
|
| 324 |
-
# Initialize the transcriber
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
| 330 |
try:
|
| 331 |
-
#
|
| 332 |
-
|
| 333 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 334 |
-
midi_output = os.path.join("outputs", f"output_{timestamp}.mid")
|
| 335 |
-
musicxml_output = os.path.join("outputs", f"output_{timestamp}.musicxml")
|
| 336 |
|
| 337 |
-
#
|
| 338 |
-
|
|
|
|
|
|
|
| 339 |
|
| 340 |
# Show success message
|
| 341 |
st.success("🎵 Transcription completed successfully!")
|
| 342 |
|
| 343 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
st.markdown("### Download Results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
-
#
|
| 347 |
-
if
|
|
|
|
|
|
|
| 348 |
st.markdown(f"**MIDI File:** {get_binary_file_downloader_html(midi_output, 'Download MIDI')}",
|
| 349 |
unsafe_allow_html=True)
|
| 350 |
|
|
|
|
| 9 |
import glob
|
| 10 |
import shutil
|
| 11 |
import time
|
| 12 |
+
from hf_transcriber import HFTranscriber
|
| 13 |
+
from transcriber import AudioTranscriber
|
| 14 |
|
| 15 |
# Configuration dictionary to store app settings
|
| 16 |
app_config = {
|
| 17 |
'RECORDING_ENABLED': False,
|
| 18 |
+
'AUDIO_DEVICES': [],
|
| 19 |
+
'DEFAULT_MODEL': 'openai/whisper-small' # Default model for transcription
|
| 20 |
}
|
| 21 |
|
| 22 |
def init_recording():
|
|
|
|
| 321 |
if 'last_recorded_audio' in st.session_state and st.session_state.last_recorded_audio:
|
| 322 |
audio_file = st.session_state.last_recorded_audio
|
| 323 |
|
| 324 |
+
# Add model selection
|
| 325 |
+
model_options = {
|
| 326 |
+
"Whisper Small": "openai/whisper-small",
|
| 327 |
+
"Whisper Base": "openai/whisper-base",
|
| 328 |
+
"Wav2Vec2 Base": "facebook/wav2vec2-base-960h",
|
| 329 |
+
"SpeechT5": "microsoft/speecht5_asr"
|
| 330 |
+
}
|
| 331 |
+
selected_model = st.selectbox(
|
| 332 |
+
"Select Transcription Model",
|
| 333 |
+
options=list(model_options.keys()),
|
| 334 |
+
index=0
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
if st.button("🎵 Transcribe Audio"):
|
| 338 |
try:
|
| 339 |
with st.spinner("Transcribing audio..."):
|
| 340 |
+
# Initialize the transcriber with the selected model
|
| 341 |
+
model_name = model_options[selected_model]
|
| 342 |
+
transcriber = HFTranscriber(model_name=model_name)
|
| 343 |
+
|
| 344 |
+
# Create output directory
|
| 345 |
+
os.makedirs("outputs", exist_ok=True)
|
| 346 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 347 |
+
|
| 348 |
try:
|
| 349 |
+
# Transcribe the audio
|
| 350 |
+
result = transcriber.transcribe_audio(audio_file)
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
# Save transcription to file
|
| 353 |
+
txt_output = os.path.join("outputs", f"transcription_{timestamp}.txt")
|
| 354 |
+
with open(txt_output, 'w', encoding='utf-8') as f:
|
| 355 |
+
f.write(result['transcription'])
|
| 356 |
|
| 357 |
# Show success message
|
| 358 |
st.success("🎵 Transcription completed successfully!")
|
| 359 |
|
| 360 |
+
# Display the transcription
|
| 361 |
+
st.markdown("### Transcription Result")
|
| 362 |
+
st.text_area("Transcription", result['transcription'], height=200)
|
| 363 |
+
|
| 364 |
+
# Show download link
|
| 365 |
st.markdown("### Download Results")
|
| 366 |
+
st.download_button(
|
| 367 |
+
label="Download Transcription",
|
| 368 |
+
data=result['transcription'],
|
| 369 |
+
file_name=f"transcription_{timestamp}.txt",
|
| 370 |
+
mime="text/plain"
|
| 371 |
+
)
|
| 372 |
|
| 373 |
+
# If we have timing information, show it
|
| 374 |
+
if 'word_timestamps' in result and result['word_timestamps']:
|
| 375 |
+
st.markdown("### Word-level Timestamps")
|
| 376 |
+
st.json(result['word_timestamps'])
|
| 377 |
st.markdown(f"**MIDI File:** {get_binary_file_downloader_html(midi_output, 'Download MIDI')}",
|
| 378 |
unsafe_allow_html=True)
|
| 379 |
|