forked from samibm23/YoutubeToNotion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarize.py
44 lines (36 loc) · 1.3 KB
/
summarize.py
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
import google.generativeai as palm
from langchain_community.document_loaders import YoutubeLoader
import config
palm.configure(api_key=config.API_Key)
models = [
m for m in palm.list_models() if "generateText" in m.supported_generation_methods
]
model = models[0].name
def summarize(text, model):
prompt = """I will give you a text extracted from a youtube video,
i want you to extract key points that text explained.
please begin each keypoint with a title in this format (## title ) then in another line you put the explenation of the concept in this format(*line1
*line2) \n"""
prompt += "\n" + text
completion = palm.generate_text(
model=model,
prompt=prompt,
# The degree of randomness of the generated text
temperature=0.2,
# The maximum length of the response
max_output_tokens=1000,
)
return completion.result
def extract_youtube(video_url):
loader = YoutubeLoader.from_youtube_url(
video_url, add_video_info=True,
language=["en", "id"],
translation="en",
)
text = loader.load()
yn_data = {
"notion_page": summarize(text[0].page_content,model),
"title": text[0].metadata["title"],
"author": text[0].metadata["author"]
}
return yn_data