LivanArzuaga commited on
Commit
f78ee2c
·
verified ·
1 Parent(s): 5064e17

Update utils_hf.py

Browse files
Files changed (1) hide show
  1. utils_hf.py +1 -60
utils_hf.py CHANGED
@@ -19,8 +19,6 @@ load_dotenv()
19
  hf_token = os.environ.get("HF_DIARIZATION_TOKEN")
20
  api_key = os.environ.get("OPENAI_API_KEY")
21
 
22
- client = Client(api_key=api_key)
23
-
24
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
25
  st.info(f"Usando dispositivo: {device}")
26
 
@@ -150,20 +148,6 @@ def transcribe_audio_whisper_lib(audio_path):
150
  st.stop()
151
 
152
 
153
- def transcribe_audio_openai(audio_path):
154
- try:
155
- with open(audio_path, "rb") as audio_file:
156
- transcript = client.audio.transcriptions.create(
157
- model="whisper-1",
158
- file=audio_file,
159
- response_format="json"
160
- )
161
- return transcript.text
162
- except Exception as e:
163
- st.error(f"Error al transcribir el audio: {e}")
164
- st.stop()
165
-
166
-
167
  def download_youtube_audio(url, progress_bar):
168
  # No incluyas la extensión '.wav' en el 'outtmpl'
169
  output_path = os.path.join('temp_audio')
@@ -242,47 +226,4 @@ class StreamlitProgressHook(ProgressHook):
242
  progress_message = f"{step_name:<20} ━ Progress data unavailable"
243
  self.progress_text.text(progress_message)
244
 
245
- # def diarize_in_segments(audio_path, segment_duration=300):
246
- # try:
247
- # audio_duration = get_audio_duration(audio_path)
248
- # diarization_segments = []
249
- # diarization_text = ""
250
- # speakers = set()
251
- #
252
- # # Procesar cada segmento por separado
253
- # for start_time in range(0, int(audio_duration), segment_duration):
254
- # end_time = min(start_time + segment_duration, audio_duration)
255
- # st.info(f"Procesando segmento desde {start_time} hasta {end_time} segundos...")
256
- #
257
- # with StreamlitProgressHook() as hook:
258
- # diarization = pyannote_pipeline({
259
- # 'audio': audio_path,
260
- # 'start': start_time,
261
- # 'end': end_time
262
- # }, hook=hook)
263
- #
264
- # for segment, _, speaker in diarization.itertracks(yield_label=True):
265
- # diarization_segments.append((segment.start, segment.end, speaker))
266
- # diarization_text += f"{segment.start:.2f} - {segment.end:.2f}: {speaker}\n"
267
- # speakers.add(speaker)
268
- #
269
- # return diarization_segments, diarization_text, speakers
270
- # except Exception as e:
271
- # st.error(f"Error al realizar la diarización de un segmento: {e}")
272
- # return None, None, 0
273
-
274
- # def transcribe_audio_whisper_transformers(audio_path):
275
- # try:
276
- # # Leer el archivo de audio y convertirlo en un numpy ndarray
277
- # audio_data, _ = sf.read(audio_path)
278
- #
279
- # # Convertir a un solo canal si es necesario
280
- # if len(audio_data.shape) > 1:
281
- # audio_data = np.mean(audio_data, axis=1)
282
- #
283
- # # Transcribir el audio usando el modelo Whisper
284
- # transcript = whisper_pipeline(audio_data, return_timestamps=True)
285
- # return transcript['text']
286
- # except Exception as e:
287
- # st.error(f"Error al transcribir el audio: {e}")
288
- # st.stop()
 
19
  hf_token = os.environ.get("HF_DIARIZATION_TOKEN")
20
  api_key = os.environ.get("OPENAI_API_KEY")
21
 
 
 
22
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
23
  st.info(f"Usando dispositivo: {device}")
24
 
 
148
  st.stop()
149
 
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  def download_youtube_audio(url, progress_bar):
152
  # No incluyas la extensión '.wav' en el 'outtmpl'
153
  output_path = os.path.join('temp_audio')
 
226
  progress_message = f"{step_name:<20} ━ Progress data unavailable"
227
  self.progress_text.text(progress_message)
228
 
229
+