son9john commited on
Commit
494d2b1
·
1 Parent(s): 447159f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -11
app.py CHANGED
@@ -10,8 +10,19 @@ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
10
  import whisper
11
 
12
  import os
13
- import dropbox
14
  import datetime
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
  ACCESS_TOKEN = os.environ["ACCESS_TOKEN"]
@@ -85,7 +96,14 @@ def transcribe(audio, text):
85
 
86
  # Add the input text to the messages list
87
  messages.append({"role": "user", "content": input_text})
88
-
 
 
 
 
 
 
 
89
  # Check if the accumulated tokens have exceeded 2096
90
  num_tokens = num_tokens_from_messages(messages)
91
  if num_tokens > 2096:
@@ -98,9 +116,19 @@ def transcribe(audio, text):
98
 
99
  chat_transcript_copy = chat_transcript
100
  chat_transcript_copy += f"Number of tokens used: {num_tokens}\n\n"
101
- filename = datetime.datetime.now().strftime("%Y%m%d%H%M_personal_history.txt")
102
- dbx.files_upload(chat_transcript_copy.encode('utf-8'), f'/{filename}', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
103
- dbx.files_upload(chat_transcript_copy.encode('utf-8'), '/personal_note_backup.txt', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
 
 
 
 
 
 
 
 
 
 
104
 
105
  if num_tokens > 2200:
106
  # Reset the messages list and answer counter
@@ -128,14 +156,27 @@ def transcribe(audio, text):
128
  chat_transcript += f"[ANSWER {answer_count}]" + message['role'] + ": " + message['content'] + "\n\n"
129
  # Append the number of tokens used to the end of the chat transcript
130
 
131
- with open("personal_note.txt", "a") as f:
132
  f.write(chat_transcript)
133
 
134
  chat_transcript_copy = chat_transcript
135
  chat_transcript_copy += f"Number of tokens used: {num_tokens}\n\n"
136
- filename = datetime.datetime.now().strftime("%Y%m%d%H_personal_note.txt")
137
- dbx.files_upload(chat_transcript_copy.encode('utf-8'), f'/{filename}', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
138
- dbx.files_upload(chat_transcript_copy.encode('utf-8'), '/personal_note.txt', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  return chat_transcript
141
 
@@ -163,8 +204,6 @@ iface.launch()
163
 
164
 
165
 
166
-
167
-
168
  # from transformers import pipeline, T5Tokenizer
169
  # import pyttsx3
170
  # import threading
 
10
  import whisper
11
 
12
  import os
 
13
  import datetime
14
+ # import dropbox
15
+ # from notion_client import Client
16
+ import notion_df
17
+
18
+
19
+ # # Define your API key
20
+
21
+ # my_API_KEY = os.environ["NOTION"]
22
+ # notion = Client(auth=my_API_KEY)
23
+ # # find the page you want to upload the file to
24
+ # page = notion.pages.retrieve(page_id="37660063895a4525b5cd8feffd43f5d5")
25
+
26
 
27
 
28
  ACCESS_TOKEN = os.environ["ACCESS_TOKEN"]
 
96
 
97
  # Add the input text to the messages list
98
  messages.append({"role": "user", "content": input_text})
99
+
100
+ # Get the current date and time in the local timezone
101
+ now_local = datetime.datetime.now()
102
+ # Create a timezone object for Eastern Time (ET)
103
+ et_tz = datetime.timezone(datetime.timedelta(hours=-5))
104
+ # Adjust the date and time to Eastern Time (ET)
105
+ now_et = now_local.astimezone(et_tz)
106
+
107
  # Check if the accumulated tokens have exceeded 2096
108
  num_tokens = num_tokens_from_messages(messages)
109
  if num_tokens > 2096:
 
116
 
117
  chat_transcript_copy = chat_transcript
118
  chat_transcript_copy += f"Number of tokens used: {num_tokens}\n\n"
119
+
120
+ # Get the current UTC time
121
+ utc_time = datetime.now(timezone.utc)
122
+ # Convert to Eastern Time Zone
123
+ eastern_time = utc_time + timedelta(hours=-5)
124
+ # Format as string (YY-MM-DD HH:MM)
125
+ published_date = eastern_time.strftime('%m-%d-%y %H:%M')
126
+
127
+ import pandas as pd
128
+ # string dataframe?
129
+ df = pd.DataFrame([chat_transcript])
130
+ notion_df.upload(df, 'https://www.notion.so/page-827360c361f347f7bfefcc6dfbd10e51', title=str(published_date), api_key=API_KEY)
131
+
132
 
133
  if num_tokens > 2200:
134
  # Reset the messages list and answer counter
 
156
  chat_transcript += f"[ANSWER {answer_count}]" + message['role'] + ": " + message['content'] + "\n\n"
157
  # Append the number of tokens used to the end of the chat transcript
158
 
159
+ with open("conversation_history.txt", "a") as f:
160
  f.write(chat_transcript)
161
 
162
  chat_transcript_copy = chat_transcript
163
  chat_transcript_copy += f"Number of tokens used: {num_tokens}\n\n"
164
+ filename = datetime.datetime.now().strftime("%m%d%y_%H:%M_conversation_history.txt")
165
+
166
+ # dbx.files_upload(chat_transcript_copy.encode('utf-8'), f'/{filename}', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
167
+ # dbx.files_upload(chat_transcript_copy.encode('utf-8'), '/conversation_history.txt', mode=dropbox.files.WriteMode.overwrite, autorename=False, client_modified=None, mute=False)
168
+
169
+ # Get the current UTC time
170
+ utc_time = datetime.now(timezone.utc)
171
+ # Convert to Eastern Time Zone
172
+ eastern_time = utc_time + timedelta(hours=-5)
173
+ # Format as string (YY-MM-DD HH:MM)
174
+ published_date = eastern_time.strftime('%m-%d-%y %H:%M')
175
+
176
+ import pandas as pd
177
+ # string dataframe?
178
+ df = pd.DataFrame([chat_transcript_copy])
179
+ notion_df.upload(df, 'https://www.notion.so/page-827360c361f347f7bfefcc6dfbd10e51', title=str(chat_transcript_copy), api_key=API_KEY)
180
 
181
  return chat_transcript
182
 
 
204
 
205
 
206
 
 
 
207
  # from transformers import pipeline, T5Tokenizer
208
  # import pyttsx3
209
  # import threading