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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -6,6 +6,7 @@ import noisereduce as nr
6
  import torch
7
  from torchaudio.pipelines import WAV2VEC2_ASR_BASE_960H
8
  from datetime import timedelta
 
9
 
10
  # Cargar el modelo de transcripción de voz
11
  bundle = WAV2VEC2_ASR_BASE_960H
@@ -63,23 +64,28 @@ def format_as_srt(transcription):
63
  return ''.join(srt_output)
64
 
65
  def process_audio(file):
66
- # Asegurarse de que el archivo de audio está siendo tratado correctamente
67
- # El archivo puede venir como una tupla (ruta, tipo) o como un solo archivo
68
- audio_file_path = file[0] if isinstance(file, tuple) else file
69
-
70
- # Comprobar si audio_file_path es realmente una cadena
71
- if not isinstance(audio_file_path, str):
72
  raise ValueError("El archivo de audio no es una cadena válida.")
73
-
 
 
 
 
74
  # Transcribir el audio y generar subtítulos
75
  transcription = transcribe_audio(audio_file_path)
76
  srt_content = format_as_srt(transcription)
77
 
78
  # Guardar el contenido SRT en un archivo
79
- with open('subtitles.srt', 'w') as f:
 
80
  f.write(srt_content)
81
 
82
- return transcription, 'subtitles.srt'
83
 
84
 
85
  # Crear la interfaz Gradio
@@ -91,4 +97,4 @@ iface = gr.Interface(
91
  description="Graba tu voz y obtén la transcripción junto con un archivo SRT de subtítulos.",
92
  )
93
 
94
- iface.launch()
 
6
  import torch
7
  from torchaudio.pipelines import WAV2VEC2_ASR_BASE_960H
8
  from datetime import timedelta
9
+ import os
10
 
11
  # Cargar el modelo de transcripción de voz
12
  bundle = WAV2VEC2_ASR_BASE_960H
 
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
 
97
  description="Graba tu voz y obtén la transcripción junto con un archivo SRT de subtítulos.",
98
  )
99
 
100
+ iface.launch(share=True)