-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsummarize.py
More file actions
38 lines (32 loc) · 1.17 KB
/
summarize.py
File metadata and controls
38 lines (32 loc) · 1.17 KB
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
import openai_summarize
from pathlib import Path
import os
import argparse
# create API key: https://platform.openai.com/account/api-keys
openai_summarizer = openai_summarize.OpenAISummarize(os.environ["OPEN_API_KEY"])
parser = argparse.ArgumentParser(description='Zusammenfassung erstellen')
params = [
{
"command_arg": "file",
"default": "2015-09-09 VI-DS-01825 Bau- und Finanzierun SAO.txt",
"help": "file to summarize"
}
]
for entry in params:
parser.add_argument('--' + entry['command_arg'],
dest=entry['command_arg'],
action='store',
default=entry['default'],
help=entry['help'])
args = parser.parse_args()
file_name = args.file
try:
with open("data/txts/{}".format(file_name), 'r') as file:
content = file.read()
summary = openai_summarizer.summarize_text(content)
Path("data/summaries").mkdir(parents=True, exist_ok=True)
path_to_txt = "data/summaries/" + file_name
with open(path_to_txt, "w") as txt_file:
txt_file.write(summary)
except:
content = '{}.txt not found>'.format(file_name)