File size: 2,048 Bytes
7eaee48
75a79b3
 
 
 
95598b6
 
 
 
 
 
 
 
 
 
75a79b3
95598b6
 
 
 
 
 
 
75a79b3
 
95598b6
 
75a79b3
6a17722
75a79b3
6a17722
75a79b3
 
95598b6
75a79b3
 
95598b6
 
 
 
 
75a79b3
 
 
 
 
95598b6
75a79b3
6a17722
75a79b3
95598b6
 
 
 
 
 
75a79b3
 
 
95598b6
75a79b3
4d6f55d
7eaee48
acc5141
75a79b3
95598b6
 
 
 
 
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
from youtube_transcript_api import YouTubeTranscriptApi
from openai import OpenAI
import gradio as gr

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 summarizer(prompt, base_url, model, api_key):
  """
  This function takes a prompt, base_url, model, and api_key as parameters and uses the OpenAI API or DeepSeek API to generate a summary based on the prompt. It returns the generated summary.
  """
  
  system_msg = "you are a youtube transcript summarizer."

  client = OpenAI(api_key = api_key, base_url=base_url)

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


def main(url, model, api_key):     
  """
  This function takes in a URL, model, and API key as parameters and returns a summary of the given transcript.
  """

  if model == "deepseek-chat":
    base_url = "https://api.deepseek.com/v1"
  
  else:
    base_url = None
  
  transcript = youtube_url(url)
  query=f"summarize this {transcript} transcript"
  summary = summarizer(query, base_url, model, api_key)
  return summary


iface = gr.Interface(
    fn=main,
    inputs=[
        gr.Textbox(label="YouTube URL", type="text"),
        gr.Dropdown(label="Model Seçimi", choices = ["deepseek-chat", "gpt-3 turbo", "gpt-3.5-turbo"]),
        gr.Textbox(label="Api Key", type="text")
    ],
    outputs="text",
    
    title="Video Özeti Oluşturucu",
    description="Bir YouTube videosunun URL'sini girin ve özetini alın."
)

iface.launch(debug = True)