Update app.py
Browse files
app.py
CHANGED
|
@@ -87,6 +87,9 @@ def format_transcript_with_speakers(transcript, diarization):
|
|
| 87 |
|
| 88 |
def transcribe_audio(audio_file, pipeline):
|
| 89 |
try:
|
|
|
|
|
|
|
|
|
|
| 90 |
print("Loading audio file...")
|
| 91 |
audio_input, sr = librosa.load(audio_file, sr=16000)
|
| 92 |
audio_input = audio_input.astype(np.float32)
|
|
@@ -188,6 +191,8 @@ def update_transcription(n_clicks, hf_token, url):
|
|
| 188 |
try:
|
| 189 |
# Initialize the speaker diarization pipeline with the provided token
|
| 190 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token=hf_token)
|
|
|
|
|
|
|
| 191 |
print("Speaker diarization pipeline initialized successfully")
|
| 192 |
|
| 193 |
transcript = transcribe_video(url, pipeline)
|
|
@@ -200,7 +205,7 @@ def update_transcription(n_clicks, hf_token, url):
|
|
| 200 |
thread.start()
|
| 201 |
thread.join()
|
| 202 |
|
| 203 |
-
transcript =
|
| 204 |
|
| 205 |
if transcript and not transcript.startswith("An error occurred"):
|
| 206 |
download_data = dict(content=transcript, filename="transcript.txt")
|
|
@@ -212,7 +217,4 @@ def update_transcription(n_clicks, hf_token, url):
|
|
| 212 |
])
|
| 213 |
]), download_data
|
| 214 |
else:
|
| 215 |
-
return transcript, None
|
| 216 |
-
|
| 217 |
-
if __name__ == '__main__':
|
| 218 |
-
app.run(debug=True, host='0.0.0.0', port=7860)
|
|
|
|
| 87 |
|
| 88 |
def transcribe_audio(audio_file, pipeline):
|
| 89 |
try:
|
| 90 |
+
if pipeline is None:
|
| 91 |
+
raise ValueError("Speaker diarization pipeline is not initialized")
|
| 92 |
+
|
| 93 |
print("Loading audio file...")
|
| 94 |
audio_input, sr = librosa.load(audio_file, sr=16000)
|
| 95 |
audio_input = audio_input.astype(np.float32)
|
|
|
|
| 191 |
try:
|
| 192 |
# Initialize the speaker diarization pipeline with the provided token
|
| 193 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token=hf_token)
|
| 194 |
+
if pipeline is None:
|
| 195 |
+
raise ValueError("Failed to initialize the speaker diarization pipeline")
|
| 196 |
print("Speaker diarization pipeline initialized successfully")
|
| 197 |
|
| 198 |
transcript = transcribe_video(url, pipeline)
|
|
|
|
| 205 |
thread.start()
|
| 206 |
thread.join()
|
| 207 |
|
| 208 |
+
transcript = thread.result if hasattr(thread, 'result') else "Transcription failed"
|
| 209 |
|
| 210 |
if transcript and not transcript.startswith("An error occurred"):
|
| 211 |
download_data = dict(content=transcript, filename="transcript.txt")
|
|
|
|
| 217 |
])
|
| 218 |
]), download_data
|
| 219 |
else:
|
| 220 |
+
return transcript, None
|
|
|
|
|
|
|
|
|