[s] fix to method
Browse files
app.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
import librosa
|
3 |
-
import io
|
4 |
from asr import transcribe_multiple_files, ASR_LANGUAGES, model
|
5 |
from lid import identify, LID_EXAMPLES
|
6 |
import logging
|
@@ -10,49 +8,55 @@ import soundfile as sf
|
|
10 |
logging.basicConfig(level=logging.DEBUG)
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
13 |
-
def safe_process_file(file_obj):
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
def transcribe_multiple_files(audio_files, lang, transcription):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
# Prepare language options for Dropdown
|
55 |
language_options = [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()]
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
mms_transcribe = gr.Interface(
|
58 |
fn=transcribe_multiple_files,
|
@@ -61,7 +65,7 @@ mms_transcribe = gr.Interface(
|
|
61 |
gr.Dropdown(
|
62 |
choices=language_options,
|
63 |
label="Language",
|
64 |
-
value=language_options[
|
65 |
),
|
66 |
gr.Textbox(label="Optional: Provide your own transcription"),
|
67 |
],
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from asr import transcribe_multiple_files, ASR_LANGUAGES, model
|
3 |
from lid import identify, LID_EXAMPLES
|
4 |
import logging
|
|
|
8 |
logging.basicConfig(level=logging.DEBUG)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
+
# def safe_process_file(file_obj):
|
12 |
+
# try:
|
13 |
+
# logger.debug(f"Processing file: {file_obj.name}")
|
14 |
|
15 |
+
# # Check if the file_obj has a 'name' attribute (NamedString)
|
16 |
+
# if hasattr(file_obj, 'name'):
|
17 |
+
# file_path = file_obj.name
|
18 |
+
# else:
|
19 |
+
# logger.error("Unexpected file object type")
|
20 |
+
# raise ValueError("Unexpected file object type")
|
21 |
|
22 |
+
# logger.debug(f"Loading audio from file path: {file_path}")
|
23 |
|
24 |
+
# # Use soundfile to read the audio file
|
25 |
+
# audio, sr = sf.read(file_path)
|
26 |
|
27 |
+
# safe_name = f"audio_{hash(file_path)}.wav"
|
28 |
+
# logger.debug(f"File processed successfully: {safe_name}")
|
29 |
+
# return audio, sr, safe_name
|
30 |
+
# except Exception as e:
|
31 |
+
# logger.error(f"Error processing file {getattr(file_obj, 'name', 'unknown')}: {str(e)}")
|
32 |
+
# raise
|
33 |
|
34 |
+
# def transcribe_multiple_files(audio_files, lang, transcription):
|
35 |
+
# transcriptions = []
|
36 |
+
# for audio_file in audio_files:
|
37 |
+
# try:
|
38 |
+
# audio, sr, safe_name = safe_process_file(audio_file)
|
39 |
+
# logger.debug(f"Transcribing file: {safe_name}")
|
40 |
+
# logger.debug(f"Language selected: {lang}")
|
41 |
+
# logger.debug(f"User-provided transcription: {transcription}")
|
42 |
|
43 |
+
# result = transcribe_multiple_files(model, audio, lang, transcription)
|
44 |
+
# logger.debug(f"Transcription result: {result}")
|
45 |
|
46 |
+
# transcriptions.append(f"File: {safe_name}\nTranscription: {result}\n")
|
47 |
+
# except Exception as e:
|
48 |
+
# logger.error(f"Error in transcription process: {str(e)}")
|
49 |
+
# transcriptions.append(f"Error processing file: {str(e)}\n")
|
50 |
+
# return "\n".join(transcriptions)
|
51 |
|
52 |
# Prepare language options for Dropdown
|
53 |
language_options = [f"{k} ({v})" for k, v in ASR_LANGUAGES.items()]
|
54 |
+
bam_index = 0
|
55 |
+
try:
|
56 |
+
bam_index = language_options.index("bam")
|
57 |
+
except ValueError:
|
58 |
+
bam_index = 0
|
59 |
+
|
60 |
|
61 |
mms_transcribe = gr.Interface(
|
62 |
fn=transcribe_multiple_files,
|
|
|
65 |
gr.Dropdown(
|
66 |
choices=language_options,
|
67 |
label="Language",
|
68 |
+
value=language_options[bam_index] if language_options else None,
|
69 |
),
|
70 |
gr.Textbox(label="Optional: Provide your own transcription"),
|
71 |
],
|