dtkne commited on
Commit
00318c5
·
verified ·
1 Parent(s): e776633

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -19
app.py CHANGED
@@ -5,29 +5,19 @@ from pytubefix import YouTube
5
  from moviepy.editor import VideoFileClip
6
  from transformers import pipeline
7
 
8
- # Ensure no unexpected input prompts
9
- os.environ["PYTHONUNBUFFERED"] = "1"
10
- os.environ["PYTHONIOENCODING"] = "utf-8"
11
-
12
- # Load Whisper model for transcription
13
  asr = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")
14
 
15
- # Load Summarization model
16
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
17
 
18
  def process_youtube_link(youtube_url):
19
  try:
20
- time.sleep(3) # Prevents rate limiting
21
-
22
- # Use OAuth for restricted videos
23
  yt = YouTube(youtube_url, use_oauth=True, allow_oauth_cache=True)
24
  title = yt.title
25
  print(f"Downloading: {title}")
26
 
27
  video_stream = yt.streams.get_highest_resolution()
28
- if not video_stream:
29
- return "Error: No available video stream", ""
30
-
31
  video_path = f"{title}.mp4"
32
  video_stream.download(filename=video_path)
33
 
@@ -43,22 +33,18 @@ def process_youtube_link(youtube_url):
43
  # Summarize Transcription
44
  summary = summarizer(transcribed_text, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]
45
 
46
- # Clean up files after processing
47
- os.remove(video_path)
48
- os.remove(audio_path)
49
-
50
  return transcribed_text, summary
51
 
52
  except Exception as e:
53
  return f"Error: {str(e)}", ""
54
 
55
- # Create Gradio Interface
56
  iface = gr.Interface(
57
  fn=process_youtube_link,
58
  inputs=gr.Textbox(label="Enter YouTube URL"),
59
  outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
60
- title="YouTube Video Transcriber & Summarizer",
61
- description="Enter a YouTube link, and this app will transcribe and summarize the audio.",
62
  )
63
 
64
  iface.launch()
 
5
  from moviepy.editor import VideoFileClip
6
  from transformers import pipeline
7
 
8
+ # Whisper model
 
 
 
 
9
  asr = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")
10
 
11
+ # Summarization model
12
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
13
 
14
  def process_youtube_link(youtube_url):
15
  try:
 
 
 
16
  yt = YouTube(youtube_url, use_oauth=True, allow_oauth_cache=True)
17
  title = yt.title
18
  print(f"Downloading: {title}")
19
 
20
  video_stream = yt.streams.get_highest_resolution()
 
 
 
21
  video_path = f"{title}.mp4"
22
  video_stream.download(filename=video_path)
23
 
 
33
  # Summarize Transcription
34
  summary = summarizer(transcribed_text, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]
35
 
 
 
 
 
36
  return transcribed_text, summary
37
 
38
  except Exception as e:
39
  return f"Error: {str(e)}", ""
40
 
41
+ # Gradio Interface
42
  iface = gr.Interface(
43
  fn=process_youtube_link,
44
  inputs=gr.Textbox(label="Enter YouTube URL"),
45
  outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
46
+ title="YouTube Video Summarizer",
47
+ description="Enter a YouTube link, and this app will summarize the content of the video.",
48
  )
49
 
50
  iface.launch()