peterpull commited on
Commit
4f6aab4
·
1 Parent(s): f7a821d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -24
app.py CHANGED
@@ -27,36 +27,23 @@ repo = Repository(
27
  use_auth_token=HF_TOKEN)
28
 
29
 
30
- def generate_html() -> str:
31
  with open(DATA_FILE) as file:
32
- rows = file.readlines()
33
- rows.reverse()
34
- if len(rows) == 0:
35
- return "no messages yet"
36
- else:
37
- html = "<div class='chatbot'>"
38
- for row in rows:
39
- row_parts = row.split(",")
40
- user = row_parts[0].strip()
41
- chatbot = row_parts[1].strip()
42
- time = row_parts[2].strip()
43
- html += "<div>"
44
- html += f"<span>{user}</span>"
45
- html += f"<span class='message'>{chatbot}</span>"
46
- html += f"<span class='time'>{time}</span>"
47
- html += "</div>"
48
- html += "</div>"
49
- return html
50
 
51
  def store_message(chatinput: str, chatresponse: str):
52
  if chatinput and chatresponse:
53
  with open(DATA_FILE, "a") as file:
54
- file.write(f"User: {chatinput}, Chatbot: {chatresponse}, Time: {str(datetime.now())}\n")
55
- # commit changes to repo
56
- commit_url = repo.push_to_hub()
57
- print(commit_url)
58
- return generate_html()
59
 
 
60
 
61
  #gets the index file which is the context data
62
  def get_index(index_file_path):
 
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"User: {user}\nChatbot: {chatbot}\nTime: {time}\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"{chatinput},{chatresponse},{datetime.now()}\n")
 
 
 
 
45
 
46
+ return generate_text()
47
 
48
  #gets the index file which is the context data
49
  def get_index(index_file_path):