Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,41 @@
|
|
1 |
-
import replicate
|
2 |
-
import gradio
|
3 |
import os
|
|
|
|
|
|
|
4 |
|
5 |
-
# Cargar
|
|
|
|
|
|
|
6 |
replicate_token = os.getenv("REPLICATE_API_TOKEN")
|
7 |
|
8 |
-
# Verifica que el token se haya cargado
|
9 |
if not replicate_token:
|
10 |
raise ValueError("No se ha encontrado el token de API de Replicate.")
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
"
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import replicate
|
3 |
+
import gradio as gr
|
4 |
+
from dotenv import load_dotenv
|
5 |
|
6 |
+
# Cargar variables de entorno desde .env
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Aseg煤rate de configurar tu REPLICATE_API_TOKEN
|
10 |
replicate_token = os.getenv("REPLICATE_API_TOKEN")
|
11 |
|
|
|
12 |
if not replicate_token:
|
13 |
raise ValueError("No se ha encontrado el token de API de Replicate.")
|
14 |
|
15 |
+
# Funci贸n para transcribir el audio
|
16 |
+
def transcribe_audio(audio_file):
|
17 |
+
with open(audio_file, "rb") as audio:
|
18 |
+
output = replicate.run(
|
19 |
+
"vaibhavs10/incredibly-fast-whisper:3ab86df6c8f54c11309d4d1f930ac292bad43ace52d10c80d87eb258b3c9f79c",
|
20 |
+
input={
|
21 |
+
"task": "transcribe",
|
22 |
+
"audio": audio, # El archivo de audio cargado en Gradio
|
23 |
+
"language": "None", # Detecta autom谩ticamente el idioma
|
24 |
+
"timestamp": "chunk", # Incluye marcas de tiempo
|
25 |
+
"batch_size": 64,
|
26 |
+
"diarise_audio": False
|
27 |
+
}
|
28 |
+
)
|
29 |
+
return output['text'] # Devuelve solo el texto transcrito
|
30 |
+
|
31 |
+
# Crea la interfaz de Gradio
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("# Transcripci贸n de Audio usando Whisper")
|
34 |
+
audio_input = gr.Audio(type="filepath", label="Sube tu archivo de audio")
|
35 |
+
output_text = gr.Textbox(label="Transcripci贸n")
|
36 |
+
|
37 |
+
transcribe_button = gr.Button("Transcribir")
|
38 |
+
transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=output_text)
|
39 |
|
40 |
+
# Ejecuta la aplicaci贸n
|
41 |
+
demo.launch()
|