Spaces:
Sleeping
Sleeping
Update requirements.txt
Browse files- requirements.txt +60 -7
requirements.txt
CHANGED
|
@@ -1,7 +1,60 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
# Asegurar instalaci贸n de moviepy y ffmpeg
|
| 5 |
+
subprocess.run(["pip", "install", "moviepy", "imageio[ffmpeg]", "imageio_ffmpeg"], check=True)
|
| 6 |
+
|
| 7 |
+
import whisper
|
| 8 |
+
import spacy
|
| 9 |
+
import language_tool_python
|
| 10 |
+
import gradio as gr
|
| 11 |
+
from moviepy.editor import VideoFileClip
|
| 12 |
+
from docx import Document
|
| 13 |
+
|
| 14 |
+
def extract_audio(video_path, audio_path):
|
| 15 |
+
try:
|
| 16 |
+
video = VideoFileClip(video_path)
|
| 17 |
+
audio = video.audio
|
| 18 |
+
audio.write_audiofile(audio_path, codec='pcm_s16le', fps=16000)
|
| 19 |
+
return True
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error al extraer audio: {e}")
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
def transcribe_audio(audio_path):
|
| 25 |
+
model = whisper.load_model("base")
|
| 26 |
+
result = model.transcribe(audio_path, word_timestamps=True)
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
def correct_text(text):
|
| 30 |
+
tool = language_tool_python.LanguageTool('es')
|
| 31 |
+
matches = tool.check(text)
|
| 32 |
+
return language_tool_python.utils.correct(text, matches)
|
| 33 |
+
|
| 34 |
+
def create_word_doc(segments, output_path):
|
| 35 |
+
doc = Document()
|
| 36 |
+
for segment in segments:
|
| 37 |
+
corrected_text = correct_text(segment['text'])
|
| 38 |
+
doc.add_paragraph(corrected_text)
|
| 39 |
+
doc.save(output_path)
|
| 40 |
+
return output_path
|
| 41 |
+
|
| 42 |
+
def process_video(video_file):
|
| 43 |
+
audio_path = video_file.replace(".mp4", ".wav")
|
| 44 |
+
word_output = video_file.replace(".mp4", "_transcription.docx")
|
| 45 |
+
|
| 46 |
+
if extract_audio(video_file, audio_path):
|
| 47 |
+
result = transcribe_audio(audio_path)
|
| 48 |
+
segments = result['segments']
|
| 49 |
+
doc_path = create_word_doc(segments, word_output)
|
| 50 |
+
return "Transcripci贸n completada.", doc_path
|
| 51 |
+
else:
|
| 52 |
+
return "Error al procesar el archivo.", None
|
| 53 |
+
|
| 54 |
+
demo = gr.Interface(
|
| 55 |
+
fn=process_video,
|
| 56 |
+
inputs=gr.File(label="Sube un archivo de video"),
|
| 57 |
+
outputs=["text", gr.File(label="Descargar transcripci贸n")]
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
demo.launch()
|