Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,21 +25,34 @@ def init_recording():
|
|
| 25 |
from hf_transcriber import HFTranscriber
|
| 26 |
from recorder import AudioRecorder, list_audio_devices
|
| 27 |
|
| 28 |
-
# Update config
|
| 29 |
-
app_config['RECORDING_ENABLED'] = True
|
| 30 |
app_config['AudioRecorder'] = AudioRecorder
|
| 31 |
app_config['list_audio_devices'] = list_audio_devices
|
| 32 |
|
| 33 |
# Try to list audio devices to verify everything works
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
return True
|
|
|
|
| 37 |
except ImportError as e:
|
| 38 |
-
st.warning(f"Some features may be limited: {str(e)}")
|
| 39 |
app_config['RECORDING_ENABLED'] = False
|
| 40 |
return False
|
| 41 |
except Exception as e:
|
| 42 |
-
st.warning(f"Audio
|
| 43 |
app_config['RECORDING_ENABLED'] = False
|
| 44 |
return False
|
| 45 |
|
|
@@ -75,7 +88,14 @@ def main():
|
|
| 75 |
st.title("🎵 Audio to Sheet Music Transcriber")
|
| 76 |
st.markdown("### Convert monophonic audio to sheet music")
|
| 77 |
|
| 78 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
if app_config['RECORDING_ENABLED']:
|
| 80 |
if 'recorder' not in st.session_state:
|
| 81 |
try:
|
|
@@ -85,24 +105,43 @@ def main():
|
|
| 85 |
st.error(f"Failed to initialize audio recorder: {str(e)}")
|
| 86 |
app_config['RECORDING_ENABLED'] = False
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
# Initialize model_name with a default value
|
| 92 |
-
model_name = "
|
| 93 |
if use_hf:
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
"Select Model",
|
| 96 |
-
|
| 97 |
index=0
|
| 98 |
)
|
|
|
|
| 99 |
|
| 100 |
# Audio Input Section
|
| 101 |
-
st.sidebar.header("Audio Input")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
| 106 |
|
| 107 |
audio_file = None
|
| 108 |
|
|
|
|
| 25 |
from hf_transcriber import HFTranscriber
|
| 26 |
from recorder import AudioRecorder, list_audio_devices
|
| 27 |
|
| 28 |
+
# Update config with recording components
|
|
|
|
| 29 |
app_config['AudioRecorder'] = AudioRecorder
|
| 30 |
app_config['list_audio_devices'] = list_audio_devices
|
| 31 |
|
| 32 |
# Try to list audio devices to verify everything works
|
| 33 |
+
try:
|
| 34 |
+
devices = list_audio_devices()
|
| 35 |
+
app_config['AUDIO_DEVICES'] = devices
|
| 36 |
+
|
| 37 |
+
if not devices or not any(d.get('max_input_channels', 0) > 0 for d in devices):
|
| 38 |
+
st.warning("⚠️ No input devices with recording capability found. Using fallback mode.")
|
| 39 |
+
app_config['RECORDING_ENABLED'] = False
|
| 40 |
+
else:
|
| 41 |
+
app_config['RECORDING_ENABLED'] = True
|
| 42 |
+
|
| 43 |
+
except Exception as e:
|
| 44 |
+
st.warning(f"⚠️ Could not detect audio devices: {str(e)}. Using fallback mode.")
|
| 45 |
+
app_config['RECORDING_ENABLED'] = False
|
| 46 |
+
app_config['AUDIO_DEVICES'] = []
|
| 47 |
|
| 48 |
return True
|
| 49 |
+
|
| 50 |
except ImportError as e:
|
| 51 |
+
st.warning(f"⚠️ Some features may be limited: {str(e)}")
|
| 52 |
app_config['RECORDING_ENABLED'] = False
|
| 53 |
return False
|
| 54 |
except Exception as e:
|
| 55 |
+
st.warning(f"⚠️ Audio initialization failed: {str(e)}. Using fallback mode.")
|
| 56 |
app_config['RECORDING_ENABLED'] = False
|
| 57 |
return False
|
| 58 |
|
|
|
|
| 88 |
st.title("🎵 Audio to Sheet Music Transcriber")
|
| 89 |
st.markdown("### Convert monophonic audio to sheet music")
|
| 90 |
|
| 91 |
+
# Show warning if no audio devices are available
|
| 92 |
+
if not app_config['RECORDING_ENABLED']:
|
| 93 |
+
st.warning("""
|
| 94 |
+
⚠️ **No audio recording devices detected**
|
| 95 |
+
You can still use this app by uploading audio files for transcription.
|
| 96 |
+
""", icon="⚠️")
|
| 97 |
+
|
| 98 |
+
# Initialize session state for recording if enabled
|
| 99 |
if app_config['RECORDING_ENABLED']:
|
| 100 |
if 'recorder' not in st.session_state:
|
| 101 |
try:
|
|
|
|
| 105 |
st.error(f"Failed to initialize audio recorder: {str(e)}")
|
| 106 |
app_config['RECORDING_ENABLED'] = False
|
| 107 |
|
| 108 |
+
# Sidebar settings
|
| 109 |
+
st.sidebar.header("🔧 Transcription Settings")
|
| 110 |
+
|
| 111 |
+
# Model selection
|
| 112 |
+
use_hf = st.sidebar.checkbox("Use Hugging Face Model", value=True,
|
| 113 |
+
help="Use pre-trained models from Hugging Face for better accuracy")
|
| 114 |
|
| 115 |
# Initialize model_name with a default value
|
| 116 |
+
model_name = "openai/whisper-small" # Default to whisper for better accuracy
|
| 117 |
if use_hf:
|
| 118 |
+
model_options = {
|
| 119 |
+
"Whisper Small (Recommended)": "openai/whisper-small",
|
| 120 |
+
"Whisper Base": "openai/whisper-base",
|
| 121 |
+
"Wav2Vec2 Base": "facebook/wav2vec2-base-960h",
|
| 122 |
+
"SpeechT5": "microsoft/speecht5_asr"
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
model_display = st.sidebar.selectbox(
|
| 126 |
"Select Model",
|
| 127 |
+
options=list(model_options.keys()),
|
| 128 |
index=0
|
| 129 |
)
|
| 130 |
+
model_name = model_options[model_display]
|
| 131 |
|
| 132 |
# Audio Input Section
|
| 133 |
+
st.sidebar.header("🎤 Audio Input")
|
| 134 |
+
|
| 135 |
+
# Input method selection
|
| 136 |
+
input_methods = ["Upload Audio File"]
|
| 137 |
+
if app_config['RECORDING_ENABLED']:
|
| 138 |
+
input_methods.append("Record Live Audio")
|
| 139 |
|
| 140 |
+
input_method = st.sidebar.radio(
|
| 141 |
+
"Choose input method:",
|
| 142 |
+
input_methods,
|
| 143 |
+
help="Select how you want to provide the audio for transcription"
|
| 144 |
+
)
|
| 145 |
|
| 146 |
audio_file = None
|
| 147 |
|