Spaces:
Sleeping
Sleeping
app.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 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 |
-
import soundfile as sf
|
| 8 |
-
from transformers import pipeline
|
| 9 |
-
|
| 10 |
-
def process_video(video_url):
|
| 11 |
-
yt = YouTube(video_url)
|
| 12 |
-
audio_file = yt.streams.filter(only_audio=True, file_extension='mp4').first().download(filename='ytaudio.mp4')
|
| 13 |
-
subprocess.run(['ffmpeg', '-i', 'ytaudio.mp4', '-acodec', 'pcm_s16le', '-ar', '16000', 'ytaudio.wav'])
|
| 14 |
-
|
| 15 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 16 |
-
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-english", device=device)
|
| 17 |
-
|
| 18 |
-
input_file = 'ytaudio.wav'
|
| 19 |
-
stream = librosa.stream(input_file, block_length=30, frame_length=16000, hop_length=16000)
|
| 20 |
-
|
| 21 |
-
full_transcript = ''
|
| 22 |
-
for i, speech in enumerate(stream):
|
| 23 |
-
sf.write(f'{i}.wav', speech, 16000)
|
| 24 |
-
transcription = model.transcribe([f'{i}.wav'])[0]['transcription']
|
| 25 |
-
full_transcript += transcription + ' '
|
| 26 |
-
|
| 27 |
-
summarization = pipeline('summarization')
|
| 28 |
-
summarized_text = summarization(full_transcript, max_length=130, min_length=30, do_sample=False)
|
| 29 |
-
return summarized_text[0]['summary_text']
|
| 30 |
-
|
| 31 |
-
iface = gr.Interface(fn=process_video, inputs="text", outputs="text", title="YouTube Video Summarizer")
|
| 32 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|