Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import os
|
|
| 4 |
import librosa
|
| 5 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
from gingerit.gingerit import GingerIt
|
| 7 |
-
from pydub import AudioSegment
|
| 8 |
from docx import Document
|
| 9 |
|
| 10 |
# Funci贸n para extraer audio de video
|
|
@@ -23,4 +22,50 @@ def transcribe_audio(audio_path):
|
|
| 23 |
audio_input, _ = librosa.load(audio_path, sr=16000)
|
| 24 |
|
| 25 |
# Preprocesar el audio para el modelo
|
| 26 |
-
inputs =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import librosa
|
| 5 |
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 6 |
from gingerit.gingerit import GingerIt
|
|
|
|
| 7 |
from docx import Document
|
| 8 |
|
| 9 |
# Funci贸n para extraer audio de video
|
|
|
|
| 22 |
audio_input, _ = librosa.load(audio_path, sr=16000)
|
| 23 |
|
| 24 |
# Preprocesar el audio para el modelo
|
| 25 |
+
inputs = processor(audio_input, return_tensors="pt", sampling_rate=16000) # Corregir aqu铆
|
| 26 |
+
|
| 27 |
+
# Realizar la transcripci贸n
|
| 28 |
+
result = model.generate(**inputs)
|
| 29 |
+
transcription = processor.decode(result[0], skip_special_tokens=True)
|
| 30 |
+
|
| 31 |
+
return transcription
|
| 32 |
+
|
| 33 |
+
# Funci贸n para corregir el texto transcrito con Gingerit
|
| 34 |
+
def correct_text(text):
|
| 35 |
+
parser = GingerIt()
|
| 36 |
+
corrected_text = parser.parse(text)['result']
|
| 37 |
+
return corrected_text
|
| 38 |
+
|
| 39 |
+
# Funci贸n principal que procesa el video
|
| 40 |
+
def process_video(video_file):
|
| 41 |
+
video_path = video_file.name
|
| 42 |
+
audio_path = os.path.splitext(video_path)[0] + '.wav'
|
| 43 |
+
|
| 44 |
+
# Extraer el audio del video
|
| 45 |
+
extract_audio(video_path, audio_path)
|
| 46 |
+
|
| 47 |
+
# Transcribir el audio
|
| 48 |
+
transcribed_text = transcribe_audio(audio_path)
|
| 49 |
+
|
| 50 |
+
# Corregir la transcripci贸n
|
| 51 |
+
corrected_text = correct_text(transcribed_text)
|
| 52 |
+
|
| 53 |
+
# Crear un documento Word con la transcripci贸n corregida
|
| 54 |
+
doc = Document()
|
| 55 |
+
doc.add_paragraph(corrected_text)
|
| 56 |
+
doc_path = "transcription.docx"
|
| 57 |
+
doc.save(doc_path)
|
| 58 |
+
|
| 59 |
+
return corrected_text, doc_path
|
| 60 |
+
|
| 61 |
+
# Interfaz de Gradio
|
| 62 |
+
demo = gr.Interface(
|
| 63 |
+
fn=process_video,
|
| 64 |
+
inputs=gr.File(label="Sube un archivo de video"),
|
| 65 |
+
outputs=[
|
| 66 |
+
gr.Textbox(label="Texto transcrito y corregido"),
|
| 67 |
+
gr.File(label="Descargar transcripci贸n Word")
|
| 68 |
+
]
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
demo.launch()
|