Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import pyannote.audio
|
|
| 3 |
import streamlit as st
|
| 4 |
from transformers import pipeline
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
-
from utils_hf import extract_audio_segment, transcribe_audio, download_youtube_audio, get_audio_duration,
|
|
|
|
| 7 |
|
| 8 |
load_dotenv()
|
| 9 |
|
|
@@ -30,38 +31,17 @@ if st.button("Transcribir y Diarizar"):
|
|
| 30 |
st.error(f"Error al procesar el video de YouTube: {e}")
|
| 31 |
st.stop()
|
| 32 |
|
| 33 |
-
with st.spinner("Realizando diarizaci贸n..."):
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
use_auth_token=token)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
speakers = set()
|
| 44 |
-
for segment, _, speaker in diarization.itertracks(yield_label=True):
|
| 45 |
-
diarization_segments.append((segment.start, segment.end, speaker))
|
| 46 |
-
diarization_text += f"{segment.start:.2f} - {segment.end:.2f}: {speaker}\n"
|
| 47 |
-
speakers.add(speaker)
|
| 48 |
-
|
| 49 |
-
num_speakers = len(speakers)
|
| 50 |
-
|
| 51 |
-
path = 'diarization.txt'
|
| 52 |
-
if os.path.exists(path):
|
| 53 |
-
os.remove(path)
|
| 54 |
-
st.success("Borrado archivo diarization.txt anterior")
|
| 55 |
-
|
| 56 |
-
with open("diarization.txt", "w") as file:
|
| 57 |
-
file.write(diarization_text)
|
| 58 |
-
|
| 59 |
-
st.text_area("Diarizaci贸n", diarization_text, height=200)
|
| 60 |
-
st.success(
|
| 61 |
-
f"Diarizaci贸n completada y guardada en diarization.txt. N煤mero de hablantes detectados: {num_speakers}")
|
| 62 |
except Exception as e:
|
| 63 |
st.error(f"Error al realizar la diarizaci贸n: {e}")
|
| 64 |
-
st.stop()
|
| 65 |
|
| 66 |
with st.spinner("Transcribiendo segmentos de audio..."):
|
| 67 |
try:
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
from transformers import pipeline
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
+
from utils_hf import ( extract_audio_segment, transcribe_audio, download_youtube_audio, get_audio_duration,
|
| 7 |
+
StreamlitProgressHook, diarize_short_segment )
|
| 8 |
|
| 9 |
load_dotenv()
|
| 10 |
|
|
|
|
| 31 |
st.error(f"Error al procesar el video de YouTube: {e}")
|
| 32 |
st.stop()
|
| 33 |
|
| 34 |
+
with st.spinner("Realizando diarizaci贸n en un segmento..."):
|
| 35 |
try:
|
| 36 |
+
diarization_segments, diarization_text, speakers = diarize_short_segment(audio_path, token, start_time=0, end_time=600)
|
|
|
|
| 37 |
|
| 38 |
+
if diarization_text:
|
| 39 |
+
st.text_area("Diarizaci贸n", diarization_text, height=200)
|
| 40 |
+
st.success(f"Diarizaci贸n completada. N煤mero de hablantes detectados: {len(speakers)}")
|
| 41 |
+
else:
|
| 42 |
+
st.error("No se pudo realizar la diarizaci贸n.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
st.error(f"Error al realizar la diarizaci贸n: {e}")
|
|
|
|
| 45 |
|
| 46 |
with st.spinner("Transcribiendo segmentos de audio..."):
|
| 47 |
try:
|