File size: 1,845 Bytes
7eaee48
75a79b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7eaee48
75a79b3
 
 
 
 
 
 
 
 
 
 
 
 
 
4d6f55d
7eaee48
acc5141
75a79b3
acc5141
8294a37
75a79b3
acc5141
 
 
fe02e1a
75a79b3
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from youtube_transcript_api import YouTubeTranscriptApi
from openai import OpenAI
import gradio as gr
import os
from dotenv import load_dotenv

load_dotenv()

api_key= os.getenv("api_key")

def youtube_url(url):
    
    """
    Function to retrieve the transcript of a YouTube video based on the provided URL.
    
    Parameters:
    url (str): The URL of the YouTube video.
    
    Returns:
    str: The transcript of the video.
    """

    transcript = ""
    list=url.split("=")
    video_id = list[1]
    list = YouTubeTranscriptApi.get_transcript(video_id, languages=['tr', 'en',"de"])
    for dict in list:
        transcript += dict["text"] + "\n"
    return transcript


def chat(prompt):

  """
  This function takes a prompt as input and uses the OpenAI API to generate a chat completion based on the prompt. It returns the summary of the chat completion.
  """

  system_msg = "you are a youtube transcript summarizer."

  client = OpenAI(api_key = api_key, base_url="https://api.deepseek.com/v1")

  completion = client.chat.completions.create(
  model="deepseek-chat",
  messages=[
      {"role": "system", "content": system_msg},
      {"role": "user", "content": prompt}
  ]
  )
  summary = completion.choices[0].message.content
  return summary


def main(url):

  """
  Function to summarize the transcript of a YouTube video using the provided URL.
  
  Parameters:
  url (str): The URL of the YouTube video.
  
  Returns:
  str: The summary of the video transcript.
  """
  
  transcript = youtube_url(url)
  query=f"summarize this {transcript} transcript"
  summary = chat(query)
  return summary


iface = gr.Interface(
    fn=main,
    inputs="text",
    outputs="text",
    
    title="Video Özeti Oluşturucu",
    description="Bir YouTube videosunun URL'sini girin ve özetini alın."
)

iface.launch(debug = True)