cfc-tech commited on
Commit
c1f076a
·
verified ·
1 Parent(s): 46f89bf
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pytube import YouTube
3
+ import subprocess
4
+ from huggingsound import SpeechRecognitionModel
5
+ import torch
6
+ import librosa
7
+ from transformers import pipeline
8
+
9
+ def process_video(video_url):
10
+ try:
11
+ # Download audio from YouTube
12
+ yt = YouTube(video_url)
13
+ audio_file = yt.streams.filter(only_audio=True, file_extension='mp4').first().download(filename='ytaudio.mp4')
14
+ except Exception as e:
15
+ return f"Error downloading audio from YouTube: {e}"
16
+
17
+ try:
18
+ # Convert to suitable format for speech recognition
19
+ subprocess.run(['ffmpeg', '-i', 'ytaudio.mp4', '-acodec', 'pcm_s16le', '-ar', '16000', 'ytaudio.wav'], check=True)
20
+ except subprocess.CalledProcessError as e:
21
+ return f"Error converting audio file: {e}"
22
+
23
+ try:
24
+ # Speech Recognition
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-english", device=device)
27
+ transcription = model.transcribe(['ytaudio.wav'])[0]['transcription']
28
+ except Exception as e:
29
+ return f"Error in speech recognition: {e}"
30
+
31
+ try:
32
+ # Summarize Transcription
33
+ summarization = pipeline('summarization')
34
+ summarized_text = summarization(transcription, max_length=130, min_length=30, do_sample=False)
35
+ return summarized_text[0]['summary_text']
36
+ except Exception as e:
37
+ return f"Error summarizing text: {e}"
38
+
39
+ iface = gr.Interface(fn=process_video, inputs=gr.inputs.Textbox(lines=2, placeholder="Enter YouTube Video URL Here..."), outputs="text", title="YouTube Video Summarizer", description="This tool extracts audio from a YouTube video, transcribes it, and provides a summary.")
40
+ iface.launch()