-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
58 lines (45 loc) · 1.59 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
from youtube_transcript_api import YouTubeTranscriptApi
import os
import openai
from dotenv import load_dotenv
load_dotenv()
st.header("Get podcast notes using AI")
st.write('GitHub repo for this project: https://github.com/abekek/podcast_notes_chatgpt')
st.markdown("""---""")
yt_id = st.text_input('YouTube video ID')
bpm = st.slider('Choose # of bullet points/minute', 1, 5)
openai.api_key = os.getenv("OPENAI_API_KEY")
if st.button('Get notes'):
result = YouTubeTranscriptApi.get_transcript(yt_id)
curr_time = 0
interval = 1
text = []
curr_text = ""
for obj in result:
curr_text += obj['text']
curr_time = obj['start']
if curr_time > interval * 600:
text.append(curr_text)
curr_text = ""
interval += 1
text.append(curr_text)
notes = ""
prompt = f"Based on the following YouTube transcript provide a {5*bpm} bullet point summary in complete sentences:\n"
st.write('Number of note blocks: ' + str(len(text)))
for i in range(len(text)):
print('test')
# res = api.send_message(prompt + text[i])['message'] + "\n"
res = openai.Completion.create(
model="text-davinci-003",
prompt=prompt + text[i] + '\nSummary:\n',
temperature=0.6,
max_tokens=576,
top_p=1,
frequency_penalty=1,
presence_penalty=1
)
res_text = res['choices'][0]['text']
st.write('Block ' + str(i+1) + '/' + str(len(text)) + ':')
st.write(res_text)
notes += res_text