Update app.py
Browse files126 unmodified lines1271281291301301311321321331341354 unmodified lines14014114214314414514614314414514614714814915015115215315415515614915715815916029 unmodified lines190191192185186187193188189190191192193194195196197198199194201195196197198199200201202203204205206126 unmodified lines
def transcribe_video(url): try: print(f"Attempting to download audio from URL: {url}") logger.info(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") 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 lines if len(transcript) < 10: raise ValueError("Transcription too short, possibly failed") print("Separating speakers...") separated_transcript = separate_speakers(transcript) return separated_transcript 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 transcript return separated_transcript except Exception as e: logger.error(f"Error during speaker separation: {str(e)}") logger.info("Returning original transcript without speaker separation") return transcript except Exception as e: error_message = f"An error occurred: {str(e)}" print(error_message) logger.error(error_message) return error_message
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])29 unmodified lines if not url: raise PreventUpdate
def transcribe(): try: transcript = transcribe_video(url) transcript = transcribe_video(url) return transcript except Exception as e: logger.exception("Error in transcription:") return f"An error occurred: {str(e)}"
# Run transcription in a separate thread thread = threading.Thread(target=transcribe) thread.start() thread.join(timeout=600) # 10 minutes timeout
if 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([ 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