Spaces:
Runtime error
Runtime error
removing double newlines, better but not totally perfect
Browse files
app.py
CHANGED
@@ -106,6 +106,7 @@ def predict(
|
|
106 |
stop_sequences=[user_name.rstrip(), assistant_name.rstrip()],
|
107 |
)
|
108 |
|
|
|
109 |
for i, response in enumerate(iterator):
|
110 |
if response.token.special:
|
111 |
continue
|
@@ -122,19 +123,27 @@ def predict(
|
|
122 |
history[-1] = partial_words
|
123 |
|
124 |
chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
|
|
|
125 |
yield chat, history, None, None, None, []
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
# Pinecone context retrieval
|
130 |
top_context_list = ta.retrieve_contexts_from_pinecone(user_question=inputs, topk=NUM_ANSWERS_GENERATED)
|
131 |
# yield chat, history, top_context_list[0], top_context_list[1], top_context_list[2], []
|
132 |
-
yield
|
133 |
|
134 |
# run CLIP
|
135 |
images_list = ta.clip_text_to_image(inputs)
|
136 |
# yield chat, history, top_context_list[0], top_context_list[1], top_context_list[2], images_list
|
137 |
-
yield
|
138 |
|
139 |
|
140 |
def reset_textbox():
|
|
|
106 |
stop_sequences=[user_name.rstrip(), assistant_name.rstrip()],
|
107 |
)
|
108 |
|
109 |
+
final_chat_response = None
|
110 |
for i, response in enumerate(iterator):
|
111 |
if response.token.special:
|
112 |
continue
|
|
|
123 |
history[-1] = partial_words
|
124 |
|
125 |
chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
|
126 |
+
final_chat_response = chat
|
127 |
yield chat, history, None, None, None, []
|
128 |
+
|
129 |
+
# Not perfect, but much better at removing all the crazy newlines.
|
130 |
+
cleaned_final_chat_response = []
|
131 |
+
for human_chat, bot_chat in final_chat_response:
|
132 |
+
human_chat = human_chat.replace("<br>", "")
|
133 |
+
human_chat = human_chat.replace("\n\n", "\n")
|
134 |
+
bot_chat = bot_chat.replace("<br>", "")
|
135 |
+
bot_chat = bot_chat.replace("\n\n", "\n")
|
136 |
+
cleaned_final_chat_response.append( (human_chat, bot_chat) )
|
137 |
|
138 |
# Pinecone context retrieval
|
139 |
top_context_list = ta.retrieve_contexts_from_pinecone(user_question=inputs, topk=NUM_ANSWERS_GENERATED)
|
140 |
# yield chat, history, top_context_list[0], top_context_list[1], top_context_list[2], []
|
141 |
+
yield cleaned_final_chat_response, history, top_context_list[0], top_context_list[1], top_context_list[2], []
|
142 |
|
143 |
# run CLIP
|
144 |
images_list = ta.clip_text_to_image(inputs)
|
145 |
# yield chat, history, top_context_list[0], top_context_list[1], top_context_list[2], images_list
|
146 |
+
yield cleaned_final_chat_response, history, top_context_list[0], top_context_list[1], top_context_list[2], images_list
|
147 |
|
148 |
|
149 |
def reset_textbox():
|