Spaces:
Runtime error
Runtime error
Eric Botti
commited on
Commit
•
fa7ab06
0
Parent(s):
initial commit
Browse files- .gitignore +4 -0
- main.py +63 -0
- requirements.txt +0 -0
- setup.py +26 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
venv
|
2 |
+
transcript.txt
|
3 |
+
notes.txt
|
4 |
+
config.ini
|
main.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# standard
|
2 |
+
import configparser
|
3 |
+
import os
|
4 |
+
import time
|
5 |
+
# 3rd party
|
6 |
+
from langchain.llms import OpenAI
|
7 |
+
from langchain import LLMChain
|
8 |
+
from langchain.document_loaders import UnstructuredFileLoader
|
9 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
10 |
+
from langchain import PromptTemplate
|
11 |
+
|
12 |
+
# read config
|
13 |
+
config = configparser.ConfigParser()
|
14 |
+
config.read('config.ini')
|
15 |
+
|
16 |
+
def summarize_chunks(chunks):
|
17 |
+
number_of_chunks = len(chunks)
|
18 |
+
print(f"Summarizing: {number_of_chunks} chunks")
|
19 |
+
chunk_summaries = []
|
20 |
+
start_time = time.time()
|
21 |
+
for i, chunk in enumerate(chunks, 1):
|
22 |
+
chunk_summaries.append(chain.run(chunk))
|
23 |
+
# info
|
24 |
+
elapsed_time = time.time() - start_time
|
25 |
+
minutes = elapsed_time // 60
|
26 |
+
print(f"Completed Summary {i}/{number_of_chunks}, {minutes:.0f} minutes {elapsed_time - 60 * minutes:.2f} seconds elapsed")
|
27 |
+
|
28 |
+
return chunk_summaries
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == '__main__':
|
32 |
+
# read config variables
|
33 |
+
if not os.getenv("OPENAI_API_KEY"):
|
34 |
+
os.environ["OPENAI_API_KEY"] = config['REQUIRED']['openai-api-key']
|
35 |
+
transcript_filepath = config['OPTIONAL']['transcript-filepath']
|
36 |
+
notes_filepath = config['OPTIONAL']['notes-filepath']
|
37 |
+
|
38 |
+
llm = OpenAI(temperature=0)
|
39 |
+
|
40 |
+
loader = UnstructuredFileLoader(transcript_filepath)
|
41 |
+
transcript = loader.load()
|
42 |
+
|
43 |
+
# Split the text into smaller chunks that can be processed by the AI
|
44 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=0)
|
45 |
+
chunks = text_splitter.split_documents(transcript)
|
46 |
+
|
47 |
+
prompt = PromptTemplate(
|
48 |
+
template="Write a concise summary of the following: {transcript}",
|
49 |
+
input_variables=['transcript']
|
50 |
+
)
|
51 |
+
|
52 |
+
chain = LLMChain(
|
53 |
+
prompt=prompt,
|
54 |
+
llm=llm,
|
55 |
+
verbose=False
|
56 |
+
)
|
57 |
+
|
58 |
+
summaries = summarize_chunks(chunks)
|
59 |
+
|
60 |
+
meeting_notes = ''.join([summary for summary in summaries])
|
61 |
+
|
62 |
+
with open(notes_filepath, 'w') as f:
|
63 |
+
f.write(meeting_notes)
|
requirements.txt
ADDED
Binary file (2.8 kB). View file
|
|
setup.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Run this script first to install requirements.txt and create config file
|
3 |
+
"""
|
4 |
+
import configparser
|
5 |
+
import sys
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
# install requirements.txt
|
9 |
+
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'])
|
10 |
+
|
11 |
+
# create default config file
|
12 |
+
config = configparser.ConfigParser()
|
13 |
+
|
14 |
+
# Required
|
15 |
+
config['REQUIRED'] = {
|
16 |
+
"openai-api-key": "Replace this with your key"
|
17 |
+
}
|
18 |
+
|
19 |
+
# Optional
|
20 |
+
config['OPTIONAL'] = {
|
21 |
+
'transcript-filepath': 'transcript.txt',
|
22 |
+
'notes-filepath': 'notes.txt'
|
23 |
+
}
|
24 |
+
|
25 |
+
with open('config.ini', 'w') as configfile:
|
26 |
+
config.write(configfile)
|