mrblackdev commited on
Commit
3a1c0f5
·
verified ·
1 Parent(s): 87b2f37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -64,28 +64,33 @@ def format_as_srt(transcription):
64
  return ''.join(srt_output)
65
 
66
  def process_audio(file):
67
- # Verificar que el archivo de audio es válido
 
 
68
  if isinstance(file, tuple):
69
  audio_file_path = file[0]
70
- elif isinstance(file, str):
71
- audio_file_path = file
72
  else:
 
 
 
 
73
  raise ValueError("El archivo de audio no es una cadena válida.")
74
-
75
- # Verificar si el archivo existe
 
76
  if not os.path.exists(audio_file_path):
77
  raise ValueError(f"El archivo {audio_file_path} no existe o no es accesible.")
78
-
79
  # Transcribir el audio y generar subtítulos
80
  transcription = transcribe_audio(audio_file_path)
81
  srt_content = format_as_srt(transcription)
82
 
83
  # Guardar el contenido SRT en un archivo
84
- srt_filename = 'subtitles.srt'
85
- with open(srt_filename, 'w') as f:
86
  f.write(srt_content)
87
 
88
- return transcription, srt_filename
 
89
 
90
 
91
  # Crear la interfaz Gradio
 
64
  return ''.join(srt_output)
65
 
66
  def process_audio(file):
67
+ # Asegurarse de que el archivo de audio está siendo tratado correctamente
68
+ # El archivo puede venir como una tupla (ruta, tipo) o como un solo archivo
69
+ # Verifica si el archivo es una tupla
70
  if isinstance(file, tuple):
71
  audio_file_path = file[0]
 
 
72
  else:
73
+ audio_file_path = file
74
+
75
+ # Comprobar si audio_file_path es realmente una cadena
76
+ if not isinstance(audio_file_path, str):
77
  raise ValueError("El archivo de audio no es una cadena válida.")
78
+
79
+ # Verificar si el archivo realmente existe
80
+ import os
81
  if not os.path.exists(audio_file_path):
82
  raise ValueError(f"El archivo {audio_file_path} no existe o no es accesible.")
83
+
84
  # Transcribir el audio y generar subtítulos
85
  transcription = transcribe_audio(audio_file_path)
86
  srt_content = format_as_srt(transcription)
87
 
88
  # Guardar el contenido SRT en un archivo
89
+ with open('subtitles.srt', 'w') as f:
 
90
  f.write(srt_content)
91
 
92
+ return transcription, 'subtitles.srt'
93
+
94
 
95
 
96
  # Crear la interfaz Gradio