Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -136,26 +136,29 @@ def render_message(history):
|
|
136 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;">
|
137 |
<div id="messages" style="display: block; margin-bottom: 10px;">"""
|
138 |
|
139 |
-
for
|
140 |
-
if
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
<div style='
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
<
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
159 |
|
160 |
messages_html += "</div></div>"
|
161 |
return messages_html
|
|
|
136 |
<div id="chatbox-container" class="chatbox" style="height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;">
|
137 |
<div id="messages" style="display: block; margin-bottom: 10px;">"""
|
138 |
|
139 |
+
for message_tuple in history:
|
140 |
+
if len(message_tuple) >= 4:
|
141 |
+
user_message, assistant_message, user_pic, assistant_pic = message_tuple[:4] # Safely unpack first 4 items
|
142 |
+
|
143 |
+
if user_message:
|
144 |
+
sanitized_message = bleach.clean(user_message, tags=allowed_tags, attributes=allowed_attributes, strip=True)
|
145 |
+
rendered_message = markdown.markdown(sanitized_message)
|
146 |
+
messages_html += f"""
|
147 |
+
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
148 |
+
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
149 |
+
<div style='color: white; white-space: pre-wrap;'>{rendered_message}</div>
|
150 |
+
</div>"""
|
151 |
+
|
152 |
+
if assistant_message:
|
153 |
+
sanitized_message = bleach.clean(assistant_message, tags=allowed_tags, attributes=allowed_attributes, strip=True)
|
154 |
+
rendered_message = markdown.markdown(sanitized_message)
|
155 |
+
messages_html += f"""
|
156 |
+
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
157 |
+
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
158 |
+
<div style='color: white; white-space: pre-wrap;'>{rendered_message}</div>
|
159 |
+
</div>"""
|
160 |
+
else:
|
161 |
+
print(f"Skipping invalid entry in history: {message_tuple}")
|
162 |
|
163 |
messages_html += "</div></div>"
|
164 |
return messages_html
|