Spaces:
PhilSpiel
/
Sleeping

PhilSpiel commited on
Commit
979a704
·
verified ·
1 Parent(s): 9a4b569

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -40
app.py CHANGED
@@ -30,7 +30,6 @@ tx = os.getenv("TX")
30
 
31
  # Assistants API prompts
32
  bullet_instructions = os.getenv("PROMPT_BULLET")
33
- summary_instructions = os.getenv("PROMPT_SUMM")
34
 
35
  # Get dateTime string to build a filename reflecting the UserID + Timestamp
36
  dt = datetime.now()
@@ -50,10 +49,8 @@ last_file_mod_time = None
50
  # Function to determine whether user is new or returning, and generate the appropriate SYSTEM PROMPT
51
  def get_system_prompt(user_id):
52
  past_summary_bullet = ""
53
- past_summary_summ = ""
54
  pics_file = ""
55
  user_summ_file_bullet = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-bullet.txt"
56
- user_summ_file_summ = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-summ.txt"
57
  pics_file_path = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-pics.txt"
58
 
59
  # Create pics file if not exist
@@ -70,11 +67,6 @@ def get_system_prompt(user_id):
70
  if os.path.exists(user_summ_file_bullet):
71
  with open(user_summ_file_bullet, "r", encoding="UTF-8") as file:
72
  past_summary_bullet = file.read().strip() # Read the contents of the summary file
73
-
74
- # Check if the summary file exists and read from it
75
- if os.path.exists(user_summ_file_summ):
76
- with open(user_summ_file_summ, "r", encoding="UTF-8") as file:
77
- past_summary_summ = file.read().strip() # Read the contents of the summary file
78
 
79
  # past_summary = past_summary_bullet + "\n" + past_summary_summ
80
  past_summary = past_summary_bullet
@@ -107,11 +99,6 @@ def on_timeout(user_id):
107
  if current_mod_time is not None and (last_file_mod_time is None or current_mod_time > last_file_mod_time):
108
  #print(f"User with ID {user_id} has been inactive, but the history file was updated. Running timeout script.")
109
  last_file_mod_time = current_mod_time
110
- # Insert your timeout script here
111
- # Construct the filename for the user's summary file & user's history file
112
- user_bullet_file = prefix + coach_code + "-" + user_id + "-bullet.txt" # Filename where the user history summary will be stored.
113
- user_summ_file = prefix + coach_code + "-" + user_id + "-summ.txt" # Filename where the user history summary will be stored.
114
- user_hist_file = prefix + coach_code + "-" + user_id + ".txt" # Filename where the user history is stored.
115
  # Construct the filename for the user's bullet file
116
  user_summ_file_bullet = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-bullet.txt"
117
 
@@ -225,21 +212,6 @@ def predict(user_input, history):
225
  if len(user_input) > max_length:
226
  user_input = ""
227
 
228
- if user_input == tx:
229
- try:
230
- # Read the contents of the user_hist_file
231
- with open(user_hist_file, "r", encoding="UTF-8") as file:
232
- file_contents = file.read()
233
-
234
- # Yield the file contents as chat output
235
- yield file_contents
236
- return
237
- except FileNotFoundError:
238
- yield "File '" + user_hist_file + "' not found."
239
- return
240
- elif len(user_input) > max_length:
241
- raise gr.Error(f"Input is TOO LONG. Max length is {max_length} characters. Try again.")
242
-
243
  global last_interaction_time, user_id, last_file_mod_time
244
  # ... [other global variables that are used]
245
 
@@ -329,22 +301,12 @@ def get_user_summary(name):
329
  user_id = name.strip().upper().replace(" ", "")
330
  name_cap = name_cap.title()
331
  summary = "Welcome! Please proceed to the '" + coach_name_long + "' tab (at top of chatbot) to chat."
332
- user_summ_file = f"{prefix}{coach_code}-{user_id}-summ.txt"
333
- if os.path.exists(user_summ_file):
334
- with open(user_summ_file, "r", encoding="UTF-8") as file:
335
- summary = file.read().strip()
336
- summary = summary.replace("User", "Client")
337
- summary = summary.replace("user", "Client")
338
- summary = summary.replace("the assistant", coach_name_short)
339
- summary = summary.replace("The assistant", coach_name_short)
340
- summary = summary.replace("- Assistant", "- Coach")
341
- summary = f"COACH: {coach_name_short}\n\nLAST ENCOUNTER: {summary}"
342
- return "Welcome! Please proceed to the '" + coach_name_long + "' tab (at top of chatbot) to chat", summary, admin()
343
 
344
  def admin():
345
  if user_id == "POIPOIPOI":
346
  # Set the directory path
347
- directory_path = prefix # different on huggingface
348
 
349
  # Get a list of all files in the directory
350
  file_list = os.listdir(directory_path)
 
30
 
31
  # Assistants API prompts
32
  bullet_instructions = os.getenv("PROMPT_BULLET")
 
33
 
34
  # Get dateTime string to build a filename reflecting the UserID + Timestamp
35
  dt = datetime.now()
 
49
  # Function to determine whether user is new or returning, and generate the appropriate SYSTEM PROMPT
50
  def get_system_prompt(user_id):
51
  past_summary_bullet = ""
 
52
  pics_file = ""
53
  user_summ_file_bullet = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-bullet.txt"
 
54
  pics_file_path = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-pics.txt"
55
 
56
  # Create pics file if not exist
 
67
  if os.path.exists(user_summ_file_bullet):
68
  with open(user_summ_file_bullet, "r", encoding="UTF-8") as file:
69
  past_summary_bullet = file.read().strip() # Read the contents of the summary file
 
 
 
 
 
70
 
71
  # past_summary = past_summary_bullet + "\n" + past_summary_summ
72
  past_summary = past_summary_bullet
 
99
  if current_mod_time is not None and (last_file_mod_time is None or current_mod_time > last_file_mod_time):
100
  #print(f"User with ID {user_id} has been inactive, but the history file was updated. Running timeout script.")
101
  last_file_mod_time = current_mod_time
 
 
 
 
 
102
  # Construct the filename for the user's bullet file
103
  user_summ_file_bullet = f"{prefix}{coach_code}-{user_id.upper().replace(' ', '')}-bullet.txt"
104
 
 
212
  if len(user_input) > max_length:
213
  user_input = ""
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  global last_interaction_time, user_id, last_file_mod_time
216
  # ... [other global variables that are used]
217
 
 
301
  user_id = name.strip().upper().replace(" ", "")
302
  name_cap = name_cap.title()
303
  summary = "Welcome! Please proceed to the '" + coach_name_long + "' tab (at top of chatbot) to chat."
304
+ return summary, admin()
 
 
 
 
 
 
 
 
 
 
305
 
306
  def admin():
307
  if user_id == "POIPOIPOI":
308
  # Set the directory path
309
+ directory_path = "" # different on huggingface
310
 
311
  # Get a list of all files in the directory
312
  file_list = os.listdir(directory_path)