Update app.py
Browse files
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
|
108 |
-
#
|
109 |
-
|
110 |
|
111 |
-
#
|
112 |
-
|
113 |
-
text = text.replace(token, "")
|
114 |
|
115 |
-
return
|
|
|
116 |
|
117 |
def upload_to_google_drive():
|
118 |
|
@@ -187,13 +188,15 @@ def generate(prompt, history):
|
|
187 |
|
188 |
# yield response
|
189 |
|
190 |
-
|
|
|
|
|
191 |
if not isFirstRun:
|
192 |
-
chat_log_history.append({"user": prompt, "bot":
|
193 |
upload_to_google_drive()
|
194 |
|
195 |
else:
|
196 |
-
chat_log_history.append({"user": firstmsg, "bot":
|
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 |
|