Athspi commited on
Commit
cf7e069
·
verified ·
1 Parent(s): 9b50ef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -42
app.py CHANGED
@@ -1,11 +1,12 @@
1
- # Dependencies:
2
- # pip install gradio faster-whisper moviepy torch
3
-
4
  import gradio as gr
5
  import torch
6
  import os
7
  from faster_whisper import WhisperModel
8
- from moviepy.video.io.VideoFileClip import VideoFileClip # Updated import
 
 
 
 
9
 
10
  # Define the model and device
11
  MODEL_NAME = "Systran/faster-whisper-large-v3"
@@ -39,7 +40,7 @@ def extract_audio_from_video(video_file):
39
  """Extract audio from a video file and save it as a WAV file."""
40
  video = VideoFileClip(video_file)
41
  audio_file = "extracted_audio.wav"
42
- video.audio.write_audiofile(audio_file, fps=16000)
43
  return audio_file
44
 
45
  def generate_subtitles(audio_file, language="Auto Detect"):
@@ -94,46 +95,16 @@ def process_video(video_file, language="Auto Detect"):
94
 
95
  return srt_file
96
 
97
- # Custom CSS for styling
98
- custom_css = """
99
- .gradio-container {
100
- background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
101
- font-family: 'Arial', sans-serif;
102
- }
103
- .header {
104
- text-align: center;
105
- padding: 20px;
106
- background: linear-gradient(135deg, #6a11cb, #2575fc);
107
- color: white;
108
- border-radius: 10px;
109
- margin-bottom: 20px;
110
- }
111
- .header h1 {
112
- font-size: 2.5rem;
113
- margin: 0;
114
- }
115
- .header p {
116
- font-size: 1.2rem;
117
- margin: 10px 0 0;
118
- }
119
- .tab {
120
- background: white;
121
- padding: 20px;
122
- border-radius: 10px;
123
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
124
- }
125
- """
126
-
127
  # Define the Gradio interface
128
- with gr.Blocks(css=custom_css, title="AutoSubGen - AI Video Subtitle Generator") as demo:
129
  # Header
130
- with gr.Column(elem_classes="header"):
131
- gr.Markdown("# AutoSubGen")
132
  gr.Markdown("### AI-Powered Video Subtitle Generator")
133
- gr.Markdown("Automatically generate subtitles for your videos in SRT format. Supports 100+ languages and auto-detection.")
134
 
135
  # Main content
136
- with gr.Tab("Generate Subtitles", elem_classes="tab"):
137
  gr.Markdown("### Upload a video file to generate subtitles.")
138
  with gr.Row():
139
  video_input = gr.Video(label="Upload Video File", scale=2)
@@ -153,5 +124,5 @@ with gr.Blocks(css=custom_css, title="AutoSubGen - AI Video Subtitle Generator")
153
  outputs=subtitle_output
154
  )
155
 
156
- # Launch the Gradio interface
157
- demo.launch()
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  import os
4
  from faster_whisper import WhisperModel
5
+ from moviepy.video.io.VideoFileClip import VideoFileClip
6
+ import logging
7
+
8
+ # Suppress moviepy logs
9
+ logging.getLogger("moviepy").setLevel(logging.ERROR)
10
 
11
  # Define the model and device
12
  MODEL_NAME = "Systran/faster-whisper-large-v3"
 
40
  """Extract audio from a video file and save it as a WAV file."""
41
  video = VideoFileClip(video_file)
42
  audio_file = "extracted_audio.wav"
43
+ video.audio.write_audiofile(audio_file, fps=16000, logger=None) # Suppress logs
44
  return audio_file
45
 
46
  def generate_subtitles(audio_file, language="Auto Detect"):
 
95
 
96
  return srt_file
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  # Define the Gradio interface
99
+ with gr.Blocks(title="AutoSubGen - AI Video Subtitle Generator") as demo:
100
  # Header
101
+ with gr.Column():
102
+ gr.Markdown("# 🎥 AutoSubGen")
103
  gr.Markdown("### AI-Powered Video Subtitle Generator")
104
+ gr.Markdown("Automatically generate subtitles for your videos in **SRT format**. Supports **100+ languages** and **auto-detection**.")
105
 
106
  # Main content
107
+ with gr.Tab("Generate Subtitles"):
108
  gr.Markdown("### Upload a video file to generate subtitles.")
109
  with gr.Row():
110
  video_input = gr.Video(label="Upload Video File", scale=2)
 
124
  outputs=subtitle_output
125
  )
126
 
127
+ # Launch the Gradio interface with a public link
128
+ demo.launch(share=True)