Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,30 @@
|
|
1 |
from youtube_transcript_api import YouTubeTranscriptApi
|
2 |
from openai import OpenAI
|
3 |
import gradio as gr
|
4 |
-
import os
|
5 |
-
from dotenv import load_dotenv
|
6 |
-
|
7 |
-
load_dotenv()
|
8 |
-
|
9 |
-
api_key= os.getenv("api_key")
|
10 |
|
11 |
def youtube_url(url):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
|
32 |
-
|
|
|
33 |
|
34 |
"""
|
35 |
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.
|
@@ -37,21 +32,20 @@ def chat(prompt):
|
|
37 |
|
38 |
system_msg = "you are a youtube transcript summarizer."
|
39 |
|
40 |
-
client = OpenAI(api_key = api_key, base_url=
|
41 |
|
42 |
completion = client.chat.completions.create(
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
)
|
49 |
summary = completion.choices[0].message.content
|
50 |
return summary
|
51 |
|
52 |
|
53 |
-
def main(url):
|
54 |
-
|
55 |
"""
|
56 |
Function to summarize the transcript of a YouTube video using the provided URL.
|
57 |
|
@@ -61,16 +55,26 @@ def main(url):
|
|
61 |
Returns:
|
62 |
str: The summary of the video transcript.
|
63 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
transcript = youtube_url(url)
|
66 |
query=f"summarize this {transcript} transcript"
|
67 |
-
summary =
|
68 |
return summary
|
69 |
|
70 |
|
71 |
iface = gr.Interface(
|
72 |
fn=main,
|
73 |
-
inputs=
|
|
|
|
|
|
|
|
|
74 |
outputs="text",
|
75 |
|
76 |
title="Video Özeti Oluşturucu",
|
|
|
1 |
from youtube_transcript_api import YouTubeTranscriptApi
|
2 |
from openai import OpenAI
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def youtube_url(url):
|
6 |
+
|
7 |
+
"""
|
8 |
+
Function to retrieve the transcript of a YouTube video based on the provided URL.
|
9 |
+
|
10 |
+
Parameters:
|
11 |
+
url (str): The URL of the YouTube video.
|
12 |
+
|
13 |
+
Returns:
|
14 |
+
str: The transcript of the video.
|
15 |
+
"""
|
16 |
|
17 |
+
transcript = ""
|
18 |
+
list=url.split("=")
|
19 |
+
video_id = list[1]
|
20 |
+
list = YouTubeTranscriptApi.get_transcript(video_id, languages=['tr', 'en',"de"])
|
21 |
+
for dict in list:
|
22 |
+
transcript += dict["text"] + "\n"
|
23 |
+
return transcript
|
24 |
|
25 |
|
26 |
+
|
27 |
+
def summarizer(prompt, base_url, model, api_key):
|
28 |
|
29 |
"""
|
30 |
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.
|
|
|
32 |
|
33 |
system_msg = "you are a youtube transcript summarizer."
|
34 |
|
35 |
+
client = OpenAI(api_key = api_key, base_url=base_url)
|
36 |
|
37 |
completion = client.chat.completions.create(
|
38 |
+
model=model,
|
39 |
+
messages=[
|
40 |
+
{"role": "system", "content": system_msg},
|
41 |
+
{"role": "user", "content": prompt}
|
42 |
+
]
|
43 |
)
|
44 |
summary = completion.choices[0].message.content
|
45 |
return summary
|
46 |
|
47 |
|
48 |
+
def main(url, model, api_key):
|
|
|
49 |
"""
|
50 |
Function to summarize the transcript of a YouTube video using the provided URL.
|
51 |
|
|
|
55 |
Returns:
|
56 |
str: The summary of the video transcript.
|
57 |
"""
|
58 |
+
|
59 |
+
if model == "deepseek-chat":
|
60 |
+
base_url = "https://api.deepseek.com/v1"
|
61 |
+
|
62 |
+
else:
|
63 |
+
base_url = None
|
64 |
|
65 |
transcript = youtube_url(url)
|
66 |
query=f"summarize this {transcript} transcript"
|
67 |
+
summary = summarizer(query, base_url, model, api_key)
|
68 |
return summary
|
69 |
|
70 |
|
71 |
iface = gr.Interface(
|
72 |
fn=main,
|
73 |
+
inputs=[
|
74 |
+
gr.Textbox(label="YouTube URL", type="text"),
|
75 |
+
gr.Dropdown(label="Model Seçimi", choices = ["deepseek-chat", "gpt-3 turbo", "gpt-3.5-turbo"]),
|
76 |
+
gr.Textbox(label="Api Key", type="text")
|
77 |
+
],
|
78 |
outputs="text",
|
79 |
|
80 |
title="Video Özeti Oluşturucu",
|