Spaces:
Build error
Build error
Update utils_hf.py
Browse files- utils_hf.py +22 -21
utils_hf.py
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import yt_dlp
|
| 3 |
import streamlit as st
|
| 4 |
import torch
|
| 5 |
import whisper
|
| 6 |
-
import
|
| 7 |
from pyannote.audio import Pipeline
|
| 8 |
from pyannote.audio.pipelines.utils.hook import ProgressHook
|
| 9 |
from moviepy.editor import AudioFileClip
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
hf_token = os.
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
pyannote_pipeline = Pipeline.from_pretrained(
|
| 14 |
"pyannote/speaker-diarization-3.1",
|
|
@@ -66,8 +78,9 @@ def process_transcripts(diarization_text, speakers):
|
|
| 66 |
|
| 67 |
|
| 68 |
def summarize_speaker_transcripts(speaker_transcripts):
|
| 69 |
-
|
| 70 |
-
api_key
|
|
|
|
| 71 |
|
| 72 |
for speaker, transcripts in speaker_transcripts.items():
|
| 73 |
full_text = ' '.join(transcripts)
|
|
@@ -75,24 +88,11 @@ def summarize_speaker_transcripts(speaker_transcripts):
|
|
| 75 |
if len(full_text) > max_tokens:
|
| 76 |
full_text = full_text[:max_tokens]
|
| 77 |
|
| 78 |
-
|
| 79 |
-
"prompt": f"Por favor, resume el siguiente texto:\n\n{full_text}",
|
| 80 |
-
"model": "gemini-1.5-pro",
|
| 81 |
-
"max_tokens": 150
|
| 82 |
-
}
|
| 83 |
|
| 84 |
-
|
| 85 |
-
"Authorization": f"Bearer {api_key}",
|
| 86 |
-
"Content-Type": "application/json"
|
| 87 |
-
}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if response.status_code == 200:
|
| 92 |
-
result = response.json()
|
| 93 |
-
return result["text"]
|
| 94 |
-
else:
|
| 95 |
-
st.error(f"{response.status_code}, {response.text}")
|
| 96 |
|
| 97 |
|
| 98 |
def diarize_full_audio(audio_path):
|
|
@@ -147,7 +147,7 @@ def transcribe_audio_whisper_lib(audio_path):
|
|
| 147 |
|
| 148 |
|
| 149 |
def download_youtube_audio(url, progress_bar):
|
| 150 |
-
|
| 151 |
output_path = os.path.join('temp_audio')
|
| 152 |
if os.path.exists(output_path + '.wav'):
|
| 153 |
os.remove(output_path + '.wav')
|
|
@@ -223,3 +223,4 @@ class StreamlitProgressHook(ProgressHook):
|
|
| 223 |
else:
|
| 224 |
progress_message = f"{step_name:<20} ━ Progress data unavailable"
|
| 225 |
self.progress_text.text(progress_message)
|
|
|
|
|
|
| 1 |
+
# import numpy as np
|
| 2 |
+
# import soundfile as sf
|
| 3 |
+
# import torchaudio
|
| 4 |
+
# from transformers import pipeline
|
| 5 |
+
|
| 6 |
import os
|
| 7 |
import yt_dlp
|
| 8 |
import streamlit as st
|
| 9 |
import torch
|
| 10 |
import whisper
|
| 11 |
+
import google.generativeai as genai
|
| 12 |
from pyannote.audio import Pipeline
|
| 13 |
from pyannote.audio.pipelines.utils.hook import ProgressHook
|
| 14 |
from moviepy.editor import AudioFileClip
|
| 15 |
+
from openai import Client
|
| 16 |
+
from dotenv import load_dotenv
|
| 17 |
+
|
| 18 |
+
load_dotenv()
|
| 19 |
|
| 20 |
+
hf_token = os.environ.get("HF_DIARIZATION_TOKEN")
|
| 21 |
+
|
| 22 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
st.info(f"Usando dispositivo: {device}")
|
| 24 |
|
| 25 |
pyannote_pipeline = Pipeline.from_pretrained(
|
| 26 |
"pyannote/speaker-diarization-3.1",
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
def summarize_speaker_transcripts(speaker_transcripts):
|
| 81 |
+
gapi_key = os.environ.get("GEMINI_API_KEY")
|
| 82 |
+
genai.configure(api_key=gapi_key)
|
| 83 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 84 |
|
| 85 |
for speaker, transcripts in speaker_transcripts.items():
|
| 86 |
full_text = ' '.join(transcripts)
|
|
|
|
| 88 |
if len(full_text) > max_tokens:
|
| 89 |
full_text = full_text[:max_tokens]
|
| 90 |
|
| 91 |
+
prompt=f"Por favor, resume el siguiente texto:\n\n{full_text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
response = model.generate_content(prompt)
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
st.text_area(f"Resumen del Hablante {speaker}", response.text, height=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
def diarize_full_audio(audio_path):
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
def download_youtube_audio(url, progress_bar):
|
| 150 |
+
# No incluyas la extensión '.wav' en el 'outtmpl'
|
| 151 |
output_path = os.path.join('temp_audio')
|
| 152 |
if os.path.exists(output_path + '.wav'):
|
| 153 |
os.remove(output_path + '.wav')
|
|
|
|
| 223 |
else:
|
| 224 |
progress_message = f"{step_name:<20} ━ Progress data unavailable"
|
| 225 |
self.progress_text.text(progress_message)
|
| 226 |
+
|