ChiBenevisamPas commited on
Commit
769d7dc
·
verified ·
1 Parent(s): a1794bc
Files changed (1) hide show
  1. app.py +30 -20
app.py CHANGED
@@ -1,26 +1,36 @@
 
1
  import gradio as gr
2
- import shutil
3
 
4
- # Function to display the video and return a downloadable file
5
- def upload_and_download(video_file):
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
- # Gradio interface
18
- interface = gr.Interface(
19
- fn=upload_and_download,
20
- inputs=gr.Video(label="Upload your video"), # Video input
21
- outputs=[gr.Video(label="Uploaded Video"), gr.File(label="Download Video")], # Show video and download link
22
- title="Video Uploader and Downloader"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  )
24
 
25
  # Launch the Gradio app
26
- interface.launch()
 
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()