Update app.py
Browse files
app.py
CHANGED
@@ -127,9 +127,9 @@ Now, please process the following transcribed text:
|
|
127 |
|
128 |
def transcribe_video(url):
|
129 |
try:
|
130 |
-
|
131 |
audio_bytes = download_audio_from_url(url)
|
132 |
-
|
133 |
|
134 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
|
135 |
AudioSegment.from_file(io.BytesIO(audio_bytes)).export(temp_audio.name, format="wav")
|
@@ -140,13 +140,21 @@ def transcribe_video(url):
|
|
140 |
if len(transcript) < 10:
|
141 |
raise ValueError("Transcription too short, possibly failed")
|
142 |
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
except Exception as e:
|
148 |
error_message = f"An error occurred: {str(e)}"
|
149 |
-
|
150 |
return error_message
|
151 |
|
152 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
@@ -182,23 +190,17 @@ def update_transcription(n_clicks, url):
|
|
182 |
if not url:
|
183 |
raise PreventUpdate
|
184 |
|
185 |
-
|
186 |
-
try:
|
187 |
-
transcript = transcribe_video(url)
|
188 |
-
return transcript
|
189 |
-
except Exception as e:
|
190 |
-
logger.exception("Error in transcription:")
|
191 |
-
return f"An error occurred: {str(e)}"
|
192 |
-
|
193 |
-
# Run transcription in a separate thread
|
194 |
-
thread = threading.Thread(target=transcribe)
|
195 |
-
thread.start()
|
196 |
-
thread.join(timeout=600) # 10 minutes timeout
|
197 |
-
|
198 |
-
if thread.is_alive():
|
199 |
-
return "Transcription timed out after 10 minutes", {'display': 'none'}
|
200 |
|
201 |
-
transcript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
if transcript and not transcript.startswith("An error occurred"):
|
204 |
return dbc.Card([
|
|
|
127 |
|
128 |
def transcribe_video(url):
|
129 |
try:
|
130 |
+
logger.info(f"Attempting to download audio from URL: {url}")
|
131 |
audio_bytes = download_audio_from_url(url)
|
132 |
+
logger.info(f"Successfully downloaded {len(audio_bytes)} bytes of audio data")
|
133 |
|
134 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
|
135 |
AudioSegment.from_file(io.BytesIO(audio_bytes)).export(temp_audio.name, format="wav")
|
|
|
140 |
if len(transcript) < 10:
|
141 |
raise ValueError("Transcription too short, possibly failed")
|
142 |
|
143 |
+
logger.info("Separating speakers...")
|
144 |
+
try:
|
145 |
+
separated_transcript = separate_speakers(transcript)
|
146 |
+
logger.info(f"Speaker separation complete. Result length: {len(separated_transcript)} characters")
|
147 |
+
if len(separated_transcript) < 10:
|
148 |
+
logger.warning("Speaker separation result too short, using original transcript")
|
149 |
+
return transcript
|
150 |
+
return separated_transcript
|
151 |
+
except Exception as e:
|
152 |
+
logger.error(f"Error during speaker separation: {str(e)}")
|
153 |
+
logger.info("Returning original transcript without speaker separation")
|
154 |
+
return transcript
|
155 |
except Exception as e:
|
156 |
error_message = f"An error occurred: {str(e)}"
|
157 |
+
logger.error(error_message)
|
158 |
return error_message
|
159 |
|
160 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
|
|
190 |
if not url:
|
191 |
raise PreventUpdate
|
192 |
|
193 |
+
transcript = transcribe_video(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
+
if transcript and not transcript.startswith("An error occurred"):
|
196 |
+
return dbc.Card([
|
197 |
+
dbc.CardBody([
|
198 |
+
html.H5("Transcription Result with Speaker Separation"),
|
199 |
+
html.Pre(transcript, style={"white-space": "pre-wrap", "word-wrap": "break-word"})
|
200 |
+
])
|
201 |
+
]), {'display': 'block'}
|
202 |
+
else:
|
203 |
+
return transcript, {'display': 'none'}
|
204 |
|
205 |
if transcript and not transcript.startswith("An error occurred"):
|
206 |
return dbc.Card([
|