-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelpers.py
More file actions
94 lines (70 loc) · 2.91 KB
/
helpers.py
File metadata and controls
94 lines (70 loc) · 2.91 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Import json module to handle json files, os and dotenv to get
environment variables, and the ai_functions to process audio files."""
import json
import os
from dotenv import load_dotenv
import ai_functions
# get assemblyAI api key
load_dotenv()
assemblyai_token = os.getenv("ASSEMBLYAI_API_KEY")
# prompt that goes to openAI
prompt = "Please provide a concise but detailed summary of this text for a technology expert"
# -------------- join session id to transcript/summary filenames ------------- #
def transcript_json(session_id):
"""Joins session id to transcript file name"""
filename = f'transcript_{session_id}.json'
return filename
def summary_json(session_id):
"""Joins session id to transcript file name"""
filename = f'summary_{session_id}.json'
return filename
# ------- function that starts everything, creating transcript/summary ------- #
def main(filename, session_id):
"""Uses ai functions to generate transcript and initial summary"""
upload_url = ai_functions.upload_file(assemblyai_token, filename)
transcript = ai_functions.create_transcript(assemblyai_token, upload_url)
with open(transcript_json(session_id), 'w', encoding='utf-8') as file:
json.dump(transcript, file)
summary = ai_functions.generate_summary(
prompt, transcript['summary'], session_id)
print("Summary:")
print(summary)
# ---------------------------------------------------------------------------- #
# html results #
# ---------------------------------------------------------------------------- #
def remake_summary(session_id):
"""Used to regenerate paragraph summary"""
file = open(transcript_json(session_id), encoding='utf-8')
data = json.load(file)
summary = ai_functions.generate_summary(
prompt, data['summary'], session_id)
return summary
def remake_with_new_prompt(user_prompt, session_id):
"""Regenerate summary with user-supplied prompt"""
file = open(transcript_json(session_id), encoding='utf-8')
data = json.load(file)
summary = ai_functions.generate_summary(
user_prompt, data['summary'], session_id)
return summary
def get_short_summary(session_id):
"""Get one-paragraph summary from openAI"""
file = open(summary_json(session_id), encoding='utf-8')
data = json.load(file)
output = f"{data}"
return output
def get_transcript(session_id):
"""Get transcript from assemblyAI"""
file = open(transcript_json(session_id), encoding='utf-8')
data = json.load(file)
utterances = data['utterances']
return utterances
def get_prompt():
"""Get default prompt"""
return prompt
def delete_files(filelist):
"""get ride of files with certain name"""
for filepath in filelist:
try:
os.remove(filepath)
except FileNotFoundError:
print(f"error while deleting file: {filepath}")