POLRAMBORA commited on
Commit
94bc14e
·
verified ·
1 Parent(s): b7116ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
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 user_message, assistant_message, user_pic, assistant_pic in history:
140
- if user_message:
141
- sanitized_message = bleach.clean(user_message, tags=allowed_tags, attributes=allowed_attributes, strip=True)
142
- rendered_message = markdown.markdown(sanitized_message)
143
-
144
- messages_html += f"""
145
- <div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
146
- <img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
147
- <div style='color: white; white-space: pre-wrap;'>{rendered_message}</div>
148
- </div>"""
149
-
150
- if assistant_message:
151
- sanitized_message = bleach.clean(assistant_message, tags=allowed_tags, attributes=allowed_attributes, strip=True)
152
- rendered_message = markdown.markdown(sanitized_message)
153
-
154
- messages_html += f"""
155
- <div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
156
- <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
157
- <div style='color: white; white-space: pre-wrap;'>{rendered_message}</div>
158
- </div>"""
 
 
 
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