Nick088 commited on
Commit
17a5d04
1 Parent(s): 99d3b92

removed yt-dlp

Browse files
Files changed (1) hide show
  1. app.py +4 -48
app.py CHANGED
@@ -4,7 +4,6 @@ import json
4
  from datetime import timedelta
5
  import tempfile
6
  import re
7
- import yt_dlp
8
  import gradio as gr
9
  import groq
10
  from groq import Groq
@@ -144,32 +143,6 @@ LANGUAGE_CODES = {
144
  }
145
 
146
 
147
- # download link input
148
- def yt_dlp_download(link):
149
- try:
150
- ydl_opts = {
151
- 'format': 'bestvideo+bestaudio/best', # Download best video and audio or best available
152
- 'outtmpl': '%(title)s.%(ext)s',
153
- 'nocheckcertificate': True,
154
- 'ignoreerrors': False,
155
- 'no_warnings': True,
156
- 'quiet': True,
157
- }
158
-
159
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
160
- ydl.download([link])
161
- result = ydl.extract_info(link, download=False)
162
- download_path = ydl.prepare_filename(result)
163
-
164
- return download_path
165
- except yt_dlp.utils.DownloadError as e:
166
- raise gr.Error(f"Download Error: {e}")
167
- except ValueError as e:
168
- raise gr.Error(f"Invalid Link or Format Error: {e}")
169
- except Exception as e:
170
- raise gr.Error(f"An unexpected error occurred: {e}")
171
-
172
-
173
  # helper functions
174
 
175
  def split_audio(input_file_path, chunk_size_mb):
@@ -292,12 +265,10 @@ def json_to_srt(transcription_json):
292
  return '\n'.join(srt_lines)
293
 
294
 
295
- def generate_subtitles(input_mode, input_file, link_input, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color):
296
- if input_mode == "Upload Video/Audio File":
297
- input_file_path = input_file
298
- elif input_mode == "Link Video/Audio":
299
- input_file_path = yt_dlp_download(link_input)
300
 
 
 
301
  processed_path, split_status = check_file(input_file_path)
302
  full_srt_content = ""
303
  total_duration = 0
@@ -506,12 +477,8 @@ with gr.Blocks(theme=theme, css=css) as interface:
506
  )
507
 
508
  with gr.Column():
509
- # Input mode selection
510
- input_mode = gr.Dropdown(choices=["Upload Video/Audio File", "Link Video/Audio"], value="Upload Video/Audio File", label="Input Mode")
511
  # Input components
512
  input_file = gr.File(label="Upload Audio/Video", file_types=[f".{ext}" for ext in ALLOWED_FILE_EXTENSIONS], visible=True)
513
- link_input_info = gr.Markdown("Using yt-dlp to download Youtube Video Links + other platform's ones. Check [all supported sites](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md)!", visible=False)
514
- link_input = gr.Textbox(label="Enter Video/Audio Link", visible=False)
515
 
516
  # Model and options
517
  model_choice_subtitles = gr.Dropdown(choices=["whisper-large-v3", "distil-whisper-large-v3-en"], value="whisper-large-v3", label="Audio Speech Recogition (ASR) Model")
@@ -542,16 +509,7 @@ with gr.Blocks(theme=theme, css=css) as interface:
542
 
543
 
544
  # Event bindings
545
-
546
- # input mode
547
- def toggle_input(mode):
548
- if mode == "Upload Video/Audio File":
549
- return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
550
- else:
551
- return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
552
-
553
- input_mode.change(fn=toggle_input, inputs=[input_mode], outputs=[input_file, link_input_info, link_input])
554
-
555
  # show video output
556
  include_video_option.change(lambda include_video: gr.update(visible=include_video), inputs=[include_video_option], outputs=[video_output])
557
  # show video output subs settings checkbox
@@ -576,9 +534,7 @@ with gr.Blocks(theme=theme, css=css) as interface:
576
  transcribe_button_subtitles.click(
577
  fn=generate_subtitles,
578
  inputs=[
579
- input_mode,
580
  input_file,
581
- link_input,
582
  transcribe_prompt_subtitles,
583
  language_subtitles,
584
  auto_detect_language_subtitles,
 
4
  from datetime import timedelta
5
  import tempfile
6
  import re
 
7
  import gradio as gr
8
  import groq
9
  from groq import Groq
 
143
  }
144
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  # helper functions
147
 
148
  def split_audio(input_file_path, chunk_size_mb):
 
265
  return '\n'.join(srt_lines)
266
 
267
 
268
+ def generate_subtitles(input_file, prompt, language, auto_detect_language, model, include_video, font_selection, font_file, font_color, font_size, outline_thickness, outline_color):
 
 
 
 
269
 
270
+ input_file_path = input_file
271
+
272
  processed_path, split_status = check_file(input_file_path)
273
  full_srt_content = ""
274
  total_duration = 0
 
477
  )
478
 
479
  with gr.Column():
 
 
480
  # Input components
481
  input_file = gr.File(label="Upload Audio/Video", file_types=[f".{ext}" for ext in ALLOWED_FILE_EXTENSIONS], visible=True)
 
 
482
 
483
  # Model and options
484
  model_choice_subtitles = gr.Dropdown(choices=["whisper-large-v3", "distil-whisper-large-v3-en"], value="whisper-large-v3", label="Audio Speech Recogition (ASR) Model")
 
509
 
510
 
511
  # Event bindings
512
+
 
 
 
 
 
 
 
 
 
513
  # show video output
514
  include_video_option.change(lambda include_video: gr.update(visible=include_video), inputs=[include_video_option], outputs=[video_output])
515
  # show video output subs settings checkbox
 
534
  transcribe_button_subtitles.click(
535
  fn=generate_subtitles,
536
  inputs=[
 
537
  input_file,
 
538
  transcribe_prompt_subtitles,
539
  language_subtitles,
540
  auto_detect_language_subtitles,