Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,26 +19,25 @@ model = load_model()
|
|
| 19 |
def extract_audio(video_path):
|
| 20 |
"""Optimized audio extraction for CPU"""
|
| 21 |
audio_path = tempfile.mktemp(suffix=".wav")
|
|
|
|
| 22 |
(
|
| 23 |
ffmpeg
|
| 24 |
.input(video_path)
|
| 25 |
.output(audio_path, ac=1, ar=16000, acodec='pcm_s16le')
|
| 26 |
.overwrite_output()
|
| 27 |
-
.run(quiet=True
|
|
|
|
| 28 |
return audio_path
|
| 29 |
|
| 30 |
-
def transcribe_video(
|
| 31 |
"""Process video and return transcript"""
|
| 32 |
start_time = time.time()
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
tmp_video.write(video_file)
|
| 37 |
-
video_path = tmp_video.name
|
| 38 |
|
| 39 |
# Extract audio
|
| 40 |
-
audio_path = extract_audio(
|
| 41 |
-
os.unlink(video_path) # Clean up video
|
| 42 |
|
| 43 |
# Transcribe
|
| 44 |
result = model(audio_path)
|
|
@@ -48,9 +47,6 @@ def transcribe_video(video_file):
|
|
| 48 |
os.unlink(audio_path)
|
| 49 |
process_time = time.time() - start_time
|
| 50 |
|
| 51 |
-
# Get file size
|
| 52 |
-
file_size = len(video_file) / (1024 * 1024) # in MB
|
| 53 |
-
|
| 54 |
return transcript, f"✅ Processed {file_size:.1f}MB video in {process_time:.1f} seconds"
|
| 55 |
|
| 56 |
# Gradio interface
|
|
@@ -60,7 +56,7 @@ with gr.Blocks(title="Free Video Transcriber", theme=gr.themes.Soft()) as demo:
|
|
| 60 |
|
| 61 |
with gr.Row():
|
| 62 |
with gr.Column():
|
| 63 |
-
video_input = gr.Video(label="Upload Video", sources=["upload"])
|
| 64 |
transcribe_btn = gr.Button("Transcribe Video", variant="primary")
|
| 65 |
|
| 66 |
with gr.Column():
|
|
@@ -69,16 +65,12 @@ with gr.Blocks(title="Free Video Transcriber", theme=gr.themes.Soft()) as demo:
|
|
| 69 |
download_btn = gr.DownloadButton(label="Download Transcript")
|
| 70 |
|
| 71 |
# Processing function
|
| 72 |
-
def process_video(
|
| 73 |
-
if
|
| 74 |
-
return "", "Please upload a video file first"
|
| 75 |
-
|
| 76 |
-
# Get video bytes
|
| 77 |
-
with open(video, "rb") as f:
|
| 78 |
-
video_bytes = f.read()
|
| 79 |
|
| 80 |
-
transcript, status = transcribe_video(
|
| 81 |
-
return transcript, status,
|
| 82 |
|
| 83 |
# Set up button actions
|
| 84 |
transcribe_btn.click(
|
|
|
|
| 19 |
def extract_audio(video_path):
|
| 20 |
"""Optimized audio extraction for CPU"""
|
| 21 |
audio_path = tempfile.mktemp(suffix=".wav")
|
| 22 |
+
# Fixed ffmpeg command syntax
|
| 23 |
(
|
| 24 |
ffmpeg
|
| 25 |
.input(video_path)
|
| 26 |
.output(audio_path, ac=1, ar=16000, acodec='pcm_s16le')
|
| 27 |
.overwrite_output()
|
| 28 |
+
.run(quiet=True)
|
| 29 |
+
)
|
| 30 |
return audio_path
|
| 31 |
|
| 32 |
+
def transcribe_video(video_file_path):
|
| 33 |
"""Process video and return transcript"""
|
| 34 |
start_time = time.time()
|
| 35 |
|
| 36 |
+
# Get file size
|
| 37 |
+
file_size = os.path.getsize(video_file_path) / (1024 * 1024) # in MB
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Extract audio
|
| 40 |
+
audio_path = extract_audio(video_file_path)
|
|
|
|
| 41 |
|
| 42 |
# Transcribe
|
| 43 |
result = model(audio_path)
|
|
|
|
| 47 |
os.unlink(audio_path)
|
| 48 |
process_time = time.time() - start_time
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
return transcript, f"✅ Processed {file_size:.1f}MB video in {process_time:.1f} seconds"
|
| 51 |
|
| 52 |
# Gradio interface
|
|
|
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
with gr.Column():
|
| 59 |
+
video_input = gr.Video(label="Upload Video", sources=["upload"], type="filepath")
|
| 60 |
transcribe_btn = gr.Button("Transcribe Video", variant="primary")
|
| 61 |
|
| 62 |
with gr.Column():
|
|
|
|
| 65 |
download_btn = gr.DownloadButton(label="Download Transcript")
|
| 66 |
|
| 67 |
# Processing function
|
| 68 |
+
def process_video(video_path):
|
| 69 |
+
if video_path is None:
|
| 70 |
+
return "", "Please upload a video file first", None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
transcript, status = transcribe_video(video_path)
|
| 73 |
+
return transcript, status, transcript
|
| 74 |
|
| 75 |
# Set up button actions
|
| 76 |
transcribe_btn.click(
|