Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ def search_youtube_videos(keyword):
|
|
11 |
video_urls = [video['link'] for video in results['result']]
|
12 |
return video_urls
|
13 |
|
14 |
-
# Function to get the transcript for a given list of video URLs
|
15 |
def get_transcript(urls):
|
16 |
contents = ''
|
17 |
for url in urls:
|
@@ -21,12 +20,12 @@ def get_transcript(urls):
|
|
21 |
text += segment['text']
|
22 |
contents += text
|
23 |
return contents
|
24 |
-
|
25 |
-
# Function to summarize text using OpenAI's API
|
26 |
def summarize_text(contents, OPENAI_API_KEY):
|
27 |
|
28 |
response = openai.ChatCompletion.create(
|
29 |
-
|
|
|
30 |
messages=[
|
31 |
{"role": "system", "content": "You are a helpful assistant."},
|
32 |
{"role": "user", "content": f"Summarize this: {contents}"}
|
@@ -37,6 +36,7 @@ def summarize_text(contents, OPENAI_API_KEY):
|
|
37 |
}
|
38 |
)
|
39 |
return response.choices[0].message['content'].strip()
|
|
|
40 |
# def summarize_text(contents):
|
41 |
# response = openai.ChatCompletion.create(
|
42 |
# engine="gpt-3.5-turbo",
|
@@ -46,12 +46,17 @@ def summarize_text(contents, OPENAI_API_KEY):
|
|
46 |
# return response.choices[0].text.strip()
|
47 |
|
48 |
# Function to integrate all the functionalities
|
|
|
49 |
def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
50 |
urls = search_youtube_videos(keyword)
|
51 |
contents = get_transcript(urls)
|
52 |
summary = summarize_text(contents,OPENAI_API_KEY)
|
53 |
return summary
|
54 |
|
|
|
|
|
|
|
|
|
55 |
# Define Gradio interface
|
56 |
iface = gr.Interface(
|
57 |
inputs=[
|
@@ -64,9 +69,7 @@ iface = gr.Interface(
|
|
64 |
fn=summarize_button_click # 클릭 이벤트를 처리하는 함수를 여기에 정의합니다.
|
65 |
)
|
66 |
|
67 |
-
|
68 |
-
summary = summarize_youtube_videos(keyword, OPENAI_API_KEY)
|
69 |
-
return summary
|
70 |
|
71 |
# Launch Gradio interface
|
72 |
iface.launch()
|
|
|
11 |
video_urls = [video['link'] for video in results['result']]
|
12 |
return video_urls
|
13 |
|
|
|
14 |
def get_transcript(urls):
|
15 |
contents = ''
|
16 |
for url in urls:
|
|
|
20 |
text += segment['text']
|
21 |
contents += text
|
22 |
return contents
|
23 |
+
|
|
|
24 |
def summarize_text(contents, OPENAI_API_KEY):
|
25 |
|
26 |
response = openai.ChatCompletion.create(
|
27 |
+
|
28 |
+
model="gpt-4-turbo-preview",
|
29 |
messages=[
|
30 |
{"role": "system", "content": "You are a helpful assistant."},
|
31 |
{"role": "user", "content": f"Summarize this: {contents}"}
|
|
|
36 |
}
|
37 |
)
|
38 |
return response.choices[0].message['content'].strip()
|
39 |
+
|
40 |
# def summarize_text(contents):
|
41 |
# response = openai.ChatCompletion.create(
|
42 |
# engine="gpt-3.5-turbo",
|
|
|
46 |
# return response.choices[0].text.strip()
|
47 |
|
48 |
# Function to integrate all the functionalities
|
49 |
+
|
50 |
def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
51 |
urls = search_youtube_videos(keyword)
|
52 |
contents = get_transcript(urls)
|
53 |
summary = summarize_text(contents,OPENAI_API_KEY)
|
54 |
return summary
|
55 |
|
56 |
+
def summarize_button_click(keyword, OPENAI_API_KEY):
|
57 |
+
summary = summarize_youtube_videos(keyword, OPENAI_API_KEY)
|
58 |
+
return summary
|
59 |
+
|
60 |
# Define Gradio interface
|
61 |
iface = gr.Interface(
|
62 |
inputs=[
|
|
|
69 |
fn=summarize_button_click # 클릭 이벤트를 처리하는 함수를 여기에 정의합니다.
|
70 |
)
|
71 |
|
72 |
+
|
|
|
|
|
73 |
|
74 |
# Launch Gradio interface
|
75 |
iface.launch()
|