Spaces:
Runtime error
Runtime error
ref without moviepy
Browse files- app.py +17 -15
- requirements.txt +0 -2
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import logging
|
2 |
-
# Отключаем спам от httpx
|
3 |
logging.getLogger("httpx").setLevel(logging.WARNING)
|
4 |
|
5 |
import gradio as gr
|
@@ -15,7 +14,6 @@ from sklearn.cluster import AgglomerativeClustering
|
|
15 |
import tempfile
|
16 |
import os
|
17 |
import subprocess
|
18 |
-
from moviepy.editor import VideoFileClip
|
19 |
|
20 |
# Initialize Whisper with flash attention
|
21 |
pipe = pipeline(
|
@@ -58,33 +56,37 @@ def format_time(seconds):
|
|
58 |
return f"{minutes:02}:{seconds:02}"
|
59 |
|
60 |
def extract_audio_from_video(video_path):
|
61 |
-
"""Extract audio from video file using ffmpeg
|
62 |
try:
|
63 |
# Create temporary file for audio
|
64 |
temp_audio = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
|
65 |
temp_audio_path = temp_audio.name
|
66 |
temp_audio.close()
|
67 |
|
68 |
-
#
|
69 |
command = [
|
70 |
'ffmpeg',
|
71 |
'-i', video_path,
|
72 |
-
'-vn',
|
73 |
-
'-acodec', 'pcm_s16le',
|
74 |
-
'-ar', '16000',
|
75 |
-
'-ac', '1',
|
76 |
-
'-y',
|
77 |
temp_audio_path
|
78 |
]
|
79 |
|
80 |
-
#
|
81 |
-
|
|
|
82 |
|
83 |
-
if
|
84 |
-
raise Exception(f"FFmpeg error: {
|
85 |
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
return temp_audio_path
|
90 |
except Exception as e:
|
|
|
1 |
import logging
|
|
|
2 |
logging.getLogger("httpx").setLevel(logging.WARNING)
|
3 |
|
4 |
import gradio as gr
|
|
|
14 |
import tempfile
|
15 |
import os
|
16 |
import subprocess
|
|
|
17 |
|
18 |
# Initialize Whisper with flash attention
|
19 |
pipe = pipeline(
|
|
|
56 |
return f"{minutes:02}:{seconds:02}"
|
57 |
|
58 |
def extract_audio_from_video(video_path):
|
59 |
+
"""Extract audio from video file using ffmpeg."""
|
60 |
try:
|
61 |
# Create temporary file for audio
|
62 |
temp_audio = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
|
63 |
temp_audio_path = temp_audio.name
|
64 |
temp_audio.close()
|
65 |
|
66 |
+
# FFmpeg command to extract audio
|
67 |
command = [
|
68 |
'ffmpeg',
|
69 |
'-i', video_path,
|
70 |
+
'-vn',
|
71 |
+
'-acodec', 'pcm_s16le',
|
72 |
+
'-ar', '16000',
|
73 |
+
'-ac', '1',
|
74 |
+
'-y',
|
75 |
temp_audio_path
|
76 |
]
|
77 |
|
78 |
+
# Run ffmpeg
|
79 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
80 |
+
stdout, stderr = process.communicate()
|
81 |
|
82 |
+
if process.returncode != 0:
|
83 |
+
raise Exception(f"FFmpeg error: {stderr.decode()}")
|
84 |
|
85 |
+
return temp_audio_path
|
86 |
+
except Exception as e:
|
87 |
+
if os.path.exists(temp_audio_path):
|
88 |
+
os.unlink(temp_audio_path)
|
89 |
+
raise gr.Error(f"Error extracting audio from video: {str(e)}")
|
90 |
|
91 |
return temp_audio_path
|
92 |
except Exception as e:
|
requirements.txt
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
transformers[torch]
|
2 |
speechbrain
|
3 |
scikit-learn
|
4 |
-
moviepy
|
5 |
-
imageio-ffmpeg
|
6 |
gradio
|
7 |
numpy
|
8 |
torchaudio
|
|
|
1 |
transformers[torch]
|
2 |
speechbrain
|
3 |
scikit-learn
|
|
|
|
|
4 |
gradio
|
5 |
numpy
|
6 |
torchaudio
|