Spaces:
Runtime error
Runtime error
Commit ·
a812039
1
Parent(s): 14da500
Add email and company_name parameters to Modal reception function call
Browse filesFiles changed (2)
- app.py+48-2
- requirements.txt+3-1
12 unmodified lines131415161718192021226 unmodified lines293031323334353637383940414212 unmodified linesimport shutilimport loggingimport gradio as grlogging.basicConfig(level=logging.DEBUG)logger = logging.getLogger(__name__)def process_audio(original_audio_path, dubbed_audio_path, email, company_name, tolerance):"""This function processes the audio files, handling the logic for duration check,6 unmodified linesmodal_environment = os.environ['MODAL_ENVIRONMENT']modal_volume = os.environ['WAVEFORM_MODAL_VOLUME']processing_id = str(int(time.time()))try:bsodtv_storage = modal.Volume.from_name(modal_volume)with bsodtv_storage.batch_upload() as batch:batch.put_file(original_audio_path, "/{}/original_audio.wav".format(processing_id))batch.put_file(dubbed_audio_path, "/{}/dubbed_audio.wav".format(processing_id))except Exception as e:logger.error(f"Error uploading audio files to Modal Storage: {e}")return "Error uploading audio files to Cloud Storage."# 3. Call modal to trigger processingtry:waveform_matching_function = modal.Function.from_name("Waveform-Matching", "reception_handler")12 unmodified lines1314151617181920212223242526272829303132333435363738394041424344454647484950516 unmodified lines5859606162636465666768697071727374757677787980818283848586878812 unmodified linesimport shutilimport loggingimport gradio as grimport numpy as npimport soundfile as sflogging.basicConfig(level=logging.DEBUG)logger = logging.getLogger(__name__)def _preprocess_audio_to_wav_pcm_mono(input_path: str) -> str:"""Convert the given audio file to a WAV file with PCM encoding and mono channel.The original sampling rate is preserved (no resampling).Returns the path to a temporary processed WAV file."""try:# Read audio with original sampling rate preserveddata, sr = sf.read(input_path, always_2d=True)except Exception as e:logger.error(f"Failed to read audio file '{input_path}': {e}")raisetry:# Downmix to mono by averaging channels (handles mono or multi-channel)mono = data.mean(axis=1)# Write as 16-bit PCM WAV to a temp pathout_path = f"/tmp/{uuid.uuid4().hex}.wav"sf.write(out_path, mono, int(sr), subtype="PCM_16", format="WAV")return out_pathexcept Exception as e:logger.error(f"Failed to write processed WAV file for '{input_path}': {e}")raisedef process_audio(original_audio_path, dubbed_audio_path, email, company_name, tolerance):"""This function processes the audio files, handling the logic for duration check,6 unmodified linesmodal_environment = os.environ['MODAL_ENVIRONMENT']modal_volume = os.environ['WAVEFORM_MODAL_VOLUME']processing_id = str(int(time.time()))# Preprocess audio files: WAV format, PCM encoding, mono, preserve original sampling ratetry:processed_original = _preprocess_audio_to_wav_pcm_mono(original_audio_path)processed_dubbed = _preprocess_audio_to_wav_pcm_mono(dubbed_audio_path)except Exception as e:logger.error(f"Error preprocessing audio files: {e}")return "Error preprocessing audio files."try:bsodtv_storage = modal.Volume.from_name(modal_volume)with bsodtv_storage.batch_upload() as batch:batch.put_file(processed_original, f"/{processing_id}/original_audio.wav")batch.put_file(processed_dubbed, f"/{processing_id}/dubbed_audio.wav")except Exception as e:logger.error(f"Error uploading audio files to Modal Storage: {e}")return "Error uploading audio files to Cloud Storage."finally:# Cleanup temporary processed filesfor p in [processed_original, processed_dubbed]:try:if p and os.path.exists(p):os.remove(p)except Exception:pass# 3. Call modal to trigger processingtry:waveform_matching_function = modal.Function.from_name("Waveform-Matching", "reception_handler")
123modalgradioopencv-python-headless12345numpymodalgradiosoundfileopencv-python-headless
app.py+48-2
requirements.txt+3-1