File size: 1,775 Bytes
3373fa0
7bd037c
3373fa0
 
a257a11
3373fa0
a257a11
 
3373fa0
a257a11
 
 
 
 
 
 
3373fa0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a257a11
 
3373fa0
 
 
 
 
 
 
 
 
a257a11
 
 
3373fa0
 
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 re
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.formatters import TextFormatter
from gradio_client import Client

# Initialize the Gradio client with your app's name
client = Client("Hwilner/hebrew_summerizer")

def summary(input_text):
    # Use the API endpoint to get the summary
    result = client.predict(
        input_text,
        api_name="/predict"
    )
    return result

def extract_video_id(url):
    # Regex to extract the video ID from various YouTube URL formats
    regex = r"(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
    match = re.search(regex, url)
    if match:
        return match.group(1)
    return None

def get_youtube_transcript(video_url):
    video_id = extract_video_id(video_url)
    if not video_id:
        return "Video ID could not be extracted."

    try:
        # Fetch the transcript
        transcript = YouTubeTranscriptApi.get_transcript(video_id)

        # Format the transcript into plain text
        formatter = TextFormatter()
        text_transcript = formatter.format_transcript(transcript)
        
        # Get the summary from the API
        summary_text = summary(text_transcript)

        return summary_text
    except Exception as e:
        return f"An error occurred: {e}"

gr.close_all()

demo = gr.Interface(fn=get_youtube_transcript,
                    inputs=[gr.Textbox(label="Input YouTube Url to summarize", lines=1)],
                    outputs=[gr.Textbox(label="Summarized text", lines=4)],
                    title="YouTube Script Summarizer - Hebrew",
                    description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE YOUTUBE VIDEO SCRIPT.")
demo.launch()