peterpull commited on
Commit
9f81ae1
·
1 Parent(s): 1c20844

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -11,7 +11,6 @@ import csv
11
 
12
  os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
13
 
14
-
15
  # Need to write to persistent dataset because cannot store temp data on spaces
16
  DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
17
  DATA_FILENAME = "data.txt"
@@ -20,19 +19,31 @@ DATA_FILE = os.path.join("data", DATA_FILENAME)
20
  # I am guessing we need a write access token.
21
  HF_TOKEN = os.environ.get("HF_TOKEN")
22
  print("HF TOKEN is none?", HF_TOKEN is None)
 
23
 
24
  repo = Repository(
25
  local_dir="data",
26
  clone_from=DATASET_REPO_URL,
27
  use_auth_token=HF_TOKEN)
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def store_message(chatinput: str, chatresponse: str):
30
  if chatinput and chatresponse:
31
  with open(DATA_FILE, "a") as file:
32
- now = datetime.now()
33
- timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
34
- file.write(f"{timestamp},{chatinput},{chatresponse}\n")
35
- print(f"Stored message: {timestamp},{chatinput},{chatresponse}")
36
 
37
 
38
  #gets the index file which is the context data
 
11
 
12
  os.environ["OPENAI_API_KEY"] = os.environ['SECRET_CODE']
13
 
 
14
  # Need to write to persistent dataset because cannot store temp data on spaces
15
  DATASET_REPO_URL = "https://huggingface.co/datasets/peterpull/MediatorBot"
16
  DATA_FILENAME = "data.txt"
 
19
  # I am guessing we need a write access token.
20
  HF_TOKEN = os.environ.get("HF_TOKEN")
21
  print("HF TOKEN is none?", HF_TOKEN is None)
22
+ print("HF hub ver", huggingface_hub.__version__)
23
 
24
  repo = Repository(
25
  local_dir="data",
26
  clone_from=DATASET_REPO_URL,
27
  use_auth_token=HF_TOKEN)
28
 
29
+
30
+ def generate_text() -> str:
31
+ with open(DATA_FILE) as file:
32
+ text = ""
33
+ for line in file:
34
+ row_parts = line.strip().split(";")
35
+ if len(row_parts) != 3:
36
+ continue
37
+ user, chatbot, time = row_parts
38
+ text += f"Time: {time}\nUser: {user}\nChatbot: {chatbot}\n\n"
39
+ return text if text else "No messages yet"
40
+
41
  def store_message(chatinput: str, chatresponse: str):
42
  if chatinput and chatresponse:
43
  with open(DATA_FILE, "a") as file:
44
+ file.write(f"{datetime.now()},{chatinput},{chatresponse}\n")
45
+
46
+ return generate_text()
 
47
 
48
 
49
  #gets the index file which is the context data