Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,21 +9,36 @@ import io
|
|
| 9 |
import glob
|
| 10 |
import shutil
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def init_recording():
|
| 16 |
-
|
| 17 |
-
# Import with error handling for Hugging Face Spaces
|
| 18 |
try:
|
|
|
|
| 19 |
from transcriber import AudioTranscriber
|
| 20 |
from hf_transcriber import HFTranscriber
|
| 21 |
from recorder import AudioRecorder, list_audio_devices
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return True
|
| 24 |
except ImportError as e:
|
| 25 |
st.warning(f"Some features may be limited: {str(e)}")
|
| 26 |
-
RECORDING_ENABLED = False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return False
|
| 28 |
|
| 29 |
# Initialize recording capability
|
|
@@ -59,10 +74,13 @@ def main():
|
|
| 59 |
st.markdown("### Convert monophonic audio to sheet music")
|
| 60 |
|
| 61 |
# Initialize session state for recording
|
| 62 |
-
if '
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
if 'recorder' not in st.session_state:
|
| 67 |
st.session_state.recorder = AudioRecorder()
|
| 68 |
if 'recording' not in st.session_state:
|
|
|
|
| 9 |
import glob
|
| 10 |
import shutil
|
| 11 |
|
| 12 |
+
# Configuration dictionary to store app settings
|
| 13 |
+
app_config = {
|
| 14 |
+
'RECORDING_ENABLED': False,
|
| 15 |
+
'AUDIO_DEVICES': []
|
| 16 |
+
}
|
| 17 |
|
| 18 |
def init_recording():
|
| 19 |
+
"""Initialize recording capability and return status."""
|
|
|
|
| 20 |
try:
|
| 21 |
+
# Import required modules
|
| 22 |
from transcriber import AudioTranscriber
|
| 23 |
from hf_transcriber import HFTranscriber
|
| 24 |
from recorder import AudioRecorder, list_audio_devices
|
| 25 |
+
|
| 26 |
+
# Update config
|
| 27 |
+
app_config['RECORDING_ENABLED'] = True
|
| 28 |
+
app_config['AudioRecorder'] = AudioRecorder
|
| 29 |
+
app_config['list_audio_devices'] = list_audio_devices
|
| 30 |
+
|
| 31 |
+
# Try to list audio devices to verify everything works
|
| 32 |
+
app_config['AUDIO_DEVICES'] = list_audio_devices()
|
| 33 |
+
|
| 34 |
return True
|
| 35 |
except ImportError as e:
|
| 36 |
st.warning(f"Some features may be limited: {str(e)}")
|
| 37 |
+
app_config['RECORDING_ENABLED'] = False
|
| 38 |
+
return False
|
| 39 |
+
except Exception as e:
|
| 40 |
+
st.warning(f"Audio device initialization failed: {str(e)}")
|
| 41 |
+
app_config['RECORDING_ENABLED'] = False
|
| 42 |
return False
|
| 43 |
|
| 44 |
# Initialize recording capability
|
|
|
|
| 74 |
st.markdown("### Convert monophonic audio to sheet music")
|
| 75 |
|
| 76 |
# Initialize session state for recording
|
| 77 |
+
if 'recorder' not in st.session_state and app_config['RECORDING_ENABLED']:
|
| 78 |
+
try:
|
| 79 |
+
st.session_state.recorder = app_config.get('AudioRecorder')()
|
| 80 |
+
st.session_state.recording = False
|
| 81 |
+
except Exception as e:
|
| 82 |
+
st.error(f"Failed to initialize audio recorder: {str(e)}")
|
| 83 |
+
app_config['RECORDING_ENABLED'] = False
|
| 84 |
if 'recorder' not in st.session_state:
|
| 85 |
st.session_state.recorder = AudioRecorder()
|
| 86 |
if 'recording' not in st.session_state:
|