Update app.py
Browse files
app.py
CHANGED
|
@@ -107,7 +107,6 @@ def transcribe(audio, text):
|
|
| 107 |
)["choices"][0]["message"]
|
| 108 |
|
| 109 |
|
| 110 |
-
|
| 111 |
# Add the system message to the messages list
|
| 112 |
messages.append({"role": "system", "content": system_message})
|
| 113 |
|
|
@@ -119,35 +118,18 @@ def transcribe(audio, text):
|
|
| 119 |
|
| 120 |
# Append the number of tokens used to the end of the chat transcript
|
| 121 |
num_tokens = num_tokens_from_messages(messages)
|
| 122 |
-
chat_transcript += f"Number of tokens used: {num_tokens}\n\n"
|
| 123 |
|
| 124 |
# Get the current time in Eastern Time (ET)
|
| 125 |
now_et = datetime.now(timezone(timedelta(hours=-5)))
|
| 126 |
# Format the time as string (YY-MM-DD HH:MM)
|
| 127 |
published_date = now_et.strftime('%m-%d-%y %H:%M')
|
|
|
|
|
|
|
| 128 |
|
| 129 |
# Upload the chat transcript to Notion
|
| 130 |
-
df = pd.DataFrame([
|
| 131 |
notion_df.upload(df, 'https://www.notion.so/personal-5e3978680ca848bda844452129955138?pvs=4', title=str(published_date), api_key=API_KEY)
|
| 132 |
|
| 133 |
-
# Reset the messages list and answer counter if the token limit is exceeded
|
| 134 |
-
if num_tokens > 2096:
|
| 135 |
-
messages = [initial_message]
|
| 136 |
-
answer_count = 0
|
| 137 |
-
else:
|
| 138 |
-
# Increment the answer counter
|
| 139 |
-
answer_count += 1
|
| 140 |
-
|
| 141 |
-
# Generate the system message using the OpenAI API
|
| 142 |
-
system_message = openai.Completion.create(
|
| 143 |
-
engine="text-davinci-002",
|
| 144 |
-
prompt=[{"text": f"{message['role']}: {message['content']}\n\n"} for message in messages],
|
| 145 |
-
temperature=0.7,
|
| 146 |
-
max_tokens=2000,
|
| 147 |
-
n=1,
|
| 148 |
-
stop=None,
|
| 149 |
-
)[0]["text"]
|
| 150 |
-
|
| 151 |
# Add the system message to the messages list
|
| 152 |
messages.append({"role": "system", "content": system_message})
|
| 153 |
|
|
|
|
| 107 |
)["choices"][0]["message"]
|
| 108 |
|
| 109 |
|
|
|
|
| 110 |
# Add the system message to the messages list
|
| 111 |
messages.append({"role": "system", "content": system_message})
|
| 112 |
|
|
|
|
| 118 |
|
| 119 |
# Append the number of tokens used to the end of the chat transcript
|
| 120 |
num_tokens = num_tokens_from_messages(messages)
|
|
|
|
| 121 |
|
| 122 |
# Get the current time in Eastern Time (ET)
|
| 123 |
now_et = datetime.now(timezone(timedelta(hours=-5)))
|
| 124 |
# Format the time as string (YY-MM-DD HH:MM)
|
| 125 |
published_date = now_et.strftime('%m-%d-%y %H:%M')
|
| 126 |
+
chat_transcript_copy = chat_transcript
|
| 127 |
+
chat_transcript_copy += f"Number of tokens used: {num_tokens}\n\n"
|
| 128 |
|
| 129 |
# Upload the chat transcript to Notion
|
| 130 |
+
df = pd.DataFrame([chat_transcript_copy])
|
| 131 |
notion_df.upload(df, 'https://www.notion.so/personal-5e3978680ca848bda844452129955138?pvs=4', title=str(published_date), api_key=API_KEY)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
# Add the system message to the messages list
|
| 134 |
messages.append({"role": "system", "content": system_message})
|
| 135 |
|