ECUiVADE commited on
Commit
e500cbb
1 Parent(s): f7183fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -12,6 +12,7 @@ import argparse
12
  from huggingface_hub import snapshot_download
13
  import random
14
  import string
 
15
 
16
  #TODO : Cleanup and comment
17
 
@@ -104,15 +105,15 @@ def search_file():
104
  return files
105
 
106
 
107
- def strip_special_tokens(text):
108
- # List of special tokens to be removed
109
- special_tokens = ["</s>", "<s>", "[INST]", "[/INST]"]
110
 
111
- # Iterate over the list of special tokens and replace each with an empty string
112
- for token in special_tokens:
113
- text = text.replace(token, "")
114
 
115
- return text
 
116
 
117
  def upload_to_google_drive():
118
 
@@ -187,13 +188,15 @@ def generate(prompt, history):
187
 
188
  # yield response
189
 
190
- chat_history.append((prompt,response))
 
 
191
  if not isFirstRun:
192
- chat_log_history.append({"user": prompt, "bot": response})
193
  upload_to_google_drive()
194
 
195
  else:
196
- chat_log_history.append({"user": firstmsg, "bot": reponse})
197
 
198
  context += response
199
 
 
12
  from huggingface_hub import snapshot_download
13
  import random
14
  import string
15
+ import re
16
 
17
  #TODO : Cleanup and comment
18
 
 
105
  return files
106
 
107
 
108
+ def strip_text(text):
109
+ # Pattern to match text inside parentheses or angle brackets and any text following angle brackets
110
+ pattern = r"\(.*?\)|<.*?>.*"
111
 
112
+ # Use re.sub() to replace the matched text with an empty string
113
+ cleaned_text = re.sub(pattern, "", text)
 
114
 
115
+ return cleaned_text
116
+
117
 
118
  def upload_to_google_drive():
119
 
 
188
 
189
  # yield response
190
 
191
+ cleaned_response = strip_text(response)
192
+
193
+ chat_history.append((prompt,cleaned_response))
194
  if not isFirstRun:
195
+ chat_log_history.append({"user": prompt, "bot": cleaned_response})
196
  upload_to_google_drive()
197
 
198
  else:
199
+ chat_log_history.append({"user": firstmsg, "bot": cleaned_response})
200
 
201
  context += response
202