new approach to null
Browse files
app.py
CHANGED
@@ -1,33 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
import librosa
|
3 |
import os
|
|
|
|
|
4 |
from asr import transcribe, ASR_LANGUAGES, model
|
5 |
from lid import identify, LID_EXAMPLES
|
6 |
|
7 |
-
def
|
8 |
try:
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
except Exception as e:
|
14 |
-
|
15 |
|
16 |
def transcribe_multiple_files(audio_files, lang, transcription):
|
17 |
transcriptions = []
|
18 |
for audio_file in audio_files:
|
19 |
try:
|
20 |
-
|
21 |
-
safe_name = safe_file_name(audio_file.name)
|
22 |
-
|
23 |
-
# Attempt to load the audio file
|
24 |
-
audio, sr = librosa.load(audio_file.name)
|
25 |
-
|
26 |
-
# Perform transcription
|
27 |
result = transcribe(model, audio, lang, transcription)
|
28 |
transcriptions.append(f"File: {safe_name}\nTranscription: {result}\n")
|
29 |
except Exception as e:
|
30 |
-
transcriptions.append(f"Error processing
|
31 |
return "\n".join(transcriptions)
|
32 |
|
33 |
mms_transcribe = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
import librosa
|
3 |
import os
|
4 |
+
import tempfile
|
5 |
+
import shutil
|
6 |
from asr import transcribe, ASR_LANGUAGES, model
|
7 |
from lid import identify, LID_EXAMPLES
|
8 |
|
9 |
+
def safe_process_file(file_obj):
|
10 |
try:
|
11 |
+
# Create a temporary directory
|
12 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
13 |
+
# Generate a safe file name
|
14 |
+
safe_name = f"audio_{hash(file_obj.name)}.wav"
|
15 |
+
temp_path = os.path.join(temp_dir, safe_name)
|
16 |
+
|
17 |
+
# Copy the file to the temporary directory
|
18 |
+
shutil.copy(file_obj.name, temp_path)
|
19 |
+
|
20 |
+
# Load the audio from the temporary file
|
21 |
+
audio, sr = librosa.load(temp_path)
|
22 |
+
|
23 |
+
return audio, sr, safe_name
|
24 |
except Exception as e:
|
25 |
+
raise Exception(f"Error processing file: {str(e)}")
|
26 |
|
27 |
def transcribe_multiple_files(audio_files, lang, transcription):
|
28 |
transcriptions = []
|
29 |
for audio_file in audio_files:
|
30 |
try:
|
31 |
+
audio, sr, safe_name = safe_process_file(audio_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
result = transcribe(model, audio, lang, transcription)
|
33 |
transcriptions.append(f"File: {safe_name}\nTranscription: {result}\n")
|
34 |
except Exception as e:
|
35 |
+
transcriptions.append(f"Error processing file: {str(e)}\n")
|
36 |
return "\n".join(transcriptions)
|
37 |
|
38 |
mms_transcribe = gr.Interface(
|