Spaces:
Runtime error
Runtime error
SRT
Browse files
app.py
CHANGED
@@ -1,26 +1,36 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import shutil
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
# Get the file name of the uploaded video
|
7 |
-
video_file_path = video_file.name
|
8 |
-
video_file_name = video_file_path.split('/')[-1]
|
9 |
-
|
10 |
-
# Create a downloadable copy of the video file
|
11 |
-
downloaded_file = f"downloaded_{video_file_name}"
|
12 |
-
shutil.copy(video_file_path, downloaded_file)
|
13 |
-
|
14 |
-
# Return the video file and a downloadable link
|
15 |
-
return video_file_path, downloaded_file
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
|
25 |
# Launch the Gradio app
|
26 |
-
|
|
|
1 |
+
import whisper
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Load the Whisper model
|
5 |
+
model = whisper.load_model("base") # Choose 'tiny', 'base', 'small', 'medium', or 'large'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def transcribe_video(video_file):
|
8 |
+
# Transcribe the video to generate subtitles
|
9 |
+
result = model.transcribe(video_file)
|
10 |
+
|
11 |
+
# Create the SRT file content
|
12 |
+
srt_content = ""
|
13 |
+
for i, segment in enumerate(result['segments']):
|
14 |
+
start = segment['start']
|
15 |
+
end = segment['end']
|
16 |
+
text = segment['text']
|
17 |
+
# Format timestamps for SRT
|
18 |
+
start_time = whisper.utils.format_timestamp(start)
|
19 |
+
end_time = whisper.utils.format_timestamp(end)
|
20 |
+
srt_content += f"{i + 1}\n"
|
21 |
+
srt_content += f"{start_time} --> {end_time}\n"
|
22 |
+
srt_content += f"{text.strip()}\n\n"
|
23 |
+
|
24 |
+
return srt_content
|
25 |
+
|
26 |
+
# Define Gradio interface
|
27 |
+
iface = gr.Interface(
|
28 |
+
fn=transcribe_video,
|
29 |
+
inputs=gr.Video(label="Upload Video"),
|
30 |
+
outputs=gr.File(label="Download Subtitles"),
|
31 |
+
title="Video Transcription to SRT",
|
32 |
+
description="Upload a video file, and this tool will transcribe it and generate SRT subtitles."
|
33 |
)
|
34 |
|
35 |
# Launch the Gradio app
|
36 |
+
iface.launch()
|