Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import torch
|
|
| 4 |
import uvicorn
|
| 5 |
import spacy
|
| 6 |
import pdfplumber
|
| 7 |
-
import moviepy.editor as mp
|
| 8 |
import librosa
|
| 9 |
import soundfile as sf
|
| 10 |
import matplotlib.pyplot as plt
|
|
@@ -20,6 +19,7 @@ from pyngrok import ngrok
|
|
| 20 |
from threading import Thread
|
| 21 |
import time
|
| 22 |
import uuid
|
|
|
|
| 23 |
|
| 24 |
# ✅ Ensure compatibility with Google Colab
|
| 25 |
try:
|
|
@@ -260,12 +260,17 @@ def extract_text_from_pdf(pdf_file):
|
|
| 260 |
raise HTTPException(status_code=400, detail=f"PDF extraction failed: {str(e)}")
|
| 261 |
|
| 262 |
def process_video_to_text(video_file_path):
|
| 263 |
-
"""Extract audio from video and convert to text."""
|
| 264 |
try:
|
| 265 |
print(f"Processing video file at {video_file_path}")
|
| 266 |
temp_audio_path = os.path.join("temp", "extracted_audio.wav")
|
| 267 |
-
video
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
print(f"Audio extracted to {temp_audio_path}")
|
| 270 |
result = speech_to_text(temp_audio_path)
|
| 271 |
transcript = result["text"]
|
|
|
|
| 4 |
import uvicorn
|
| 5 |
import spacy
|
| 6 |
import pdfplumber
|
|
|
|
| 7 |
import librosa
|
| 8 |
import soundfile as sf
|
| 9 |
import matplotlib.pyplot as plt
|
|
|
|
| 19 |
from threading import Thread
|
| 20 |
import time
|
| 21 |
import uuid
|
| 22 |
+
import subprocess # Used for running ffmpeg commands
|
| 23 |
|
| 24 |
# ✅ Ensure compatibility with Google Colab
|
| 25 |
try:
|
|
|
|
| 260 |
raise HTTPException(status_code=400, detail=f"PDF extraction failed: {str(e)}")
|
| 261 |
|
| 262 |
def process_video_to_text(video_file_path):
|
| 263 |
+
"""Extract audio from video using ffmpeg and convert to text."""
|
| 264 |
try:
|
| 265 |
print(f"Processing video file at {video_file_path}")
|
| 266 |
temp_audio_path = os.path.join("temp", "extracted_audio.wav")
|
| 267 |
+
# Use ffmpeg command to extract audio from the video file
|
| 268 |
+
cmd = [
|
| 269 |
+
"ffmpeg", "-i", video_file_path, "-vn",
|
| 270 |
+
"-acodec", "pcm_s16le", "-ar", "44100", "-ac", "2",
|
| 271 |
+
temp_audio_path, "-y"
|
| 272 |
+
]
|
| 273 |
+
subprocess.run(cmd, check=True)
|
| 274 |
print(f"Audio extracted to {temp_audio_path}")
|
| 275 |
result = speech_to_text(temp_audio_path)
|
| 276 |
transcript = result["text"]
|