File size: 1,705 Bytes
356bab3
949b582
5d6bc67
949b582
 
 
93d849e
b51711d
949b582
 
 
 
 
79348af
356bab3
a952e20
 
356bab3
949b582
356bab3
949b582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356bab3
 
 
 
949b582
 
356bab3
949b582
 
 
 
 
356bab3
 
949b582
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import torch
import os
import subprocess
from pytubefix import YouTube
from moviepy.editor import VideoFileClip
from transformers import pipeline

# Ensure required packages are installed inside Hugging Face Spaces
subprocess.run(["pip", "install", "pytubefix", "moviepy", "transformers", "torchaudio"], check=True)

# Load Whisper model for transcription
asr = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")

# Load Summarization model
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")


def process_youtube_link(youtube_url):
    try:
        # Download YouTube Video
        yt = YouTube(youtube_url)
        video_stream = yt.streams.filter(only_audio=True).first()
        video_path = video_stream.download(filename="video.mp4")

        # Extract Audio
        audio_path = "audio.wav"
        video = VideoFileClip(video_path)
        video.audio.write_audiofile(audio_path)

        # Transcribe Audio
        transcription = asr(audio_path)
        transcribed_text = transcription["text"]

        # Summarize Transcription
        summary = summarizer(transcribed_text, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]

        return transcribed_text, summary

    except Exception as e:
        return f"Error: {str(e)}", ""


# Create Gradio Interface
iface = gr.Interface(
    fn=process_youtube_link,
    inputs=gr.Textbox(label="Enter YouTube URL"),
    outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
    title="YouTube Video Transcriber & Summarizer",
    description="Enter a YouTube link, and this app will transcribe and summarize the audio.",
)

iface.launch()