File size: 1,656 Bytes
95aa78d
 
 
 
dfd7edf
 
30ce89b
95aa78d
480ec28
 
 
 
 
 
 
 
95aa78d
 
 
480ec28
95aa78d
 
 
 
 
 
 
30ce89b
95aa78d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
import gradio as gr
from langchain_groq import ChatGroq
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
import os

api_key = os.getenv('GROQ_API_KEY')

def get_transcript(video_url):
    from langchain_community.document_loaders import YoutubeLoader
    loader = YoutubeLoader.from_youtube_url(
        video_url, add_video_info=False
    )
    document = loader.load()
    transcript = document[0].page_content
    return transcript


def summarize_video(video_url, language):
    transcript = get_transcript(video_url)

    model = ChatGroq(
        model="llama-3.1-70b-versatile",
        temperature=0,
        max_tokens=None,
        timeout=None,
        max_retries=2,
        api_key=api_key
    )

    system_template = """Below you will see a text. Read the text. First provide the major points that they discuss and then provide summaries for each major point. Your response should be in the language specified below. 
    Transcript: {transcript}
    Language: {language}"""

    prompt_template = ChatPromptTemplate.from_messages(
        [("system", system_template)]
    )

    parser = StrOutputParser()

    chain = prompt_template | model | parser

    response = chain.invoke({"transcript": transcript, "language": language})
    return response


iface = gr.Interface(
    fn=summarize_video,
    inputs=[
        gr.Textbox(label="YouTube Video URL"),
        gr.Textbox(label="Language for Summary")
    ],
    outputs="text",
    title="YouTube Video Summarizer",
    description="Enter a YouTube video URL and the desired language for the summary."
)

iface.launch()