bomolopuu commited on
Commit
62fc325
·
1 Parent(s): b97df14

[s] fix to method

Browse files
Files changed (1) hide show
  1. app.py +40 -36
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
- try:
15
- logger.debug(f"Processing file: {file_obj.name}")
16
 
17
- # Check if the file_obj has a 'name' attribute (NamedString)
18
- if hasattr(file_obj, 'name'):
19
- file_path = file_obj.name
20
- else:
21
- logger.error("Unexpected file object type")
22
- raise ValueError("Unexpected file object type")
23
 
24
- logger.debug(f"Loading audio from file path: {file_path}")
25
 
26
- # Use soundfile to read the audio file
27
- audio, sr = sf.read(file_path)
28
 
29
- safe_name = f"audio_{hash(file_path)}.wav"
30
- logger.debug(f"File processed successfully: {safe_name}")
31
- return audio, sr, safe_name
32
- except Exception as e:
33
- logger.error(f"Error processing file {getattr(file_obj, 'name', 'unknown')}: {str(e)}")
34
- raise
35
 
36
- def transcribe_multiple_files(audio_files, lang, transcription):
37
- transcriptions = []
38
- for audio_file in audio_files:
39
- try:
40
- audio, sr, safe_name = safe_process_file(audio_file)
41
- logger.debug(f"Transcribing file: {safe_name}")
42
- logger.debug(f"Language selected: {lang}")
43
- logger.debug(f"User-provided transcription: {transcription}")
44
 
45
- result = transcribe_multiple_files(model, audio, lang, transcription)
46
- logger.debug(f"Transcription result: {result}")
47
 
48
- transcriptions.append(f"File: {safe_name}\nTranscription: {result}\n")
49
- except Exception as e:
50
- logger.error(f"Error in transcription process: {str(e)}")
51
- transcriptions.append(f"Error processing file: {str(e)}\n")
52
- return "\n".join(transcriptions)
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[0] if language_options else None,
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
  ],