Update app.py
Browse files126 unmodified lines1271281291301311321331341354 unmodified lines14014114214314414514614714814915015115229 unmodified lines182183184185186187188189190191192193194195196197198199200201202203204126 unmodified linesdef transcribe_video(url):try:print(f"Attempting to download audio from URL: {url}")audio_bytes = download_audio_from_url(url)print(f"Successfully downloaded {len(audio_bytes)} bytes of audio data")with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:AudioSegment.from_file(io.BytesIO(audio_bytes)).export(temp_audio.name, format="wav")4 unmodified linesif len(transcript) < 10:raise ValueError("Transcription too short, possibly failed")print("Separating speakers...")separated_transcript = separate_speakers(transcript)return separated_transcriptexcept Exception as e:error_message = f"An error occurred: {str(e)}"print(error_message)return error_messageapp = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])29 unmodified linesif not url:raise PreventUpdatedef transcribe():try:transcript = transcribe_video(url)return transcriptexcept Exception as e:logger.exception("Error in transcription:")return f"An error occurred: {str(e)}"# Run transcription in a separate threadthread = threading.Thread(target=transcribe)thread.start()thread.join(timeout=600) # 10 minutes timeoutif thread.is_alive():return "Transcription timed out after 10 minutes", {'display': 'none'}transcript = getattr(thread, 'result', "Transcription failed")if transcript and not transcript.startswith("An error occurred"):return dbc.Card([126 unmodified lines1271281291301311321331341354 unmodified lines14014114214314414514614714814915015115215315415515615715815916029 unmodified lines190191192193194195196197198199200201202203204205206126 unmodified linesdef transcribe_video(url):try:logger.info(f"Attempting to download audio from URL: {url}")audio_bytes = download_audio_from_url(url)logger.info(f"Successfully downloaded {len(audio_bytes)} bytes of audio data")with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:AudioSegment.from_file(io.BytesIO(audio_bytes)).export(temp_audio.name, format="wav")4 unmodified linesif len(transcript) < 10:raise ValueError("Transcription too short, possibly failed")logger.info("Separating speakers...")try:separated_transcript = separate_speakers(transcript)logger.info(f"Speaker separation complete. Result length: {len(separated_transcript)} characters")if len(separated_transcript) < 10:logger.warning("Speaker separation result too short, using original transcript")return transcriptreturn separated_transcriptexcept Exception as e:logger.error(f"Error during speaker separation: {str(e)}")logger.info("Returning original transcript without speaker separation")return transcriptexcept Exception as e:error_message = f"An error occurred: {str(e)}"logger.error(error_message)return error_messageapp = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])29 unmodified linesif not url:raise PreventUpdatetranscript = transcribe_video(url)if transcript and not transcript.startswith("An error occurred"):return dbc.Card([dbc.CardBody([html.H5("Transcription Result with Speaker Separation"),html.Pre(transcript, style={"white-space": "pre-wrap", "word-wrap": "break-word"})])]), {'display': 'block'}else:return transcript, {'display': 'none'}if transcript and not transcript.startswith("An error occurred"):return dbc.Card([
app.py+25-23