POLRAMBORA commited on
Commit
7cc787f
·
verified ·
1 Parent(s): 676013c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -34
app.py CHANGED
@@ -122,49 +122,33 @@ def render_message(history):
122
  <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;">
123
  <div id="messages" style="display: block; margin-bottom: 10px;">"""
124
 
125
- seen_messages = set()
126
-
127
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
128
- if user_message and ("user", user_message) not in seen_messages:
129
- seen_messages.add(("user", user_message))
 
130
  messages_html += f"""
131
- <div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
132
- <img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
133
- <div style='color: white; white-space: pre-wrap;'>{user_message}</div>
134
  </div>"""
135
 
136
- if assistant_message and ("assistant", assistant_message) not in seen_messages:
137
- seen_messages.add(("assistant", assistant_message))
 
138
  messages_html += f"""
139
- <div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
140
- <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
141
- <div style='color: white; white-space: pre-wrap;'>{assistant_message}</div>
142
  </div>"""
143
 
144
  messages_html += "</div></div>"
 
145
 
146
- mathjax_script = """
147
- <script type="text/javascript">
148
- MathJax = {
149
- tex: {
150
- inlineMath: [['\\(', '\\)']],
151
- displayMath: [
152
- ['\\[', '\\]'],
153
- ['\\begin{equation}', '\\end{equation}'],
154
- ['\\begin{align}', '\\end{align}'],
155
- ['\\begin{alignat}', '\\end{alignat}'],
156
- ['\\begin{gather}', '\\end{gather}'],
157
- ['\\begin{CD}', '\\end{CD}']
158
- ],
159
- processEscapes: true
160
- },
161
- svg: { fontCache: 'global' }
162
- };
163
- </script>
164
- <script type="text/javascript" async
165
- src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-svg.js"></script>
166
- """
167
- return messages_html + mathjax_script
168
 
169
 
170
  def escape_html(unsafe_text):
 
122
  <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;">
123
  <div id="messages" style="display: block; margin-bottom: 10px;">"""
124
 
125
+ seen_messages = set()
 
126
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
127
+ if user_message and user_message not in seen_messages:
128
+ seen_messages.add(user_message)
129
+ user_message_html = escape_html(user_message)
130
  messages_html += f"""
131
+ <div style='display: flex; align-items: center; margin-bottom: 10px;'>
132
+ <img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
133
+ <span style='color: white; white-space: pre-wrap;'>{user_message_html}</span>
134
  </div>"""
135
 
136
+ if assistant_message and assistant_message not in seen_messages:
137
+ seen_messages.add(assistant_message)
138
+ assistant_message_html = escape_html(assistant_message)
139
  messages_html += f"""
140
+ <div style='display: flex; align-items: center; margin-bottom: 10px;'>
141
+ <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
142
+ <span style='color: white; white-space: pre-wrap;'>{assistant_message_html}</span>
143
  </div>"""
144
 
145
  messages_html += "</div></div>"
146
+ return messages_html
147
 
148
+
149
+ def escape_html(unsafe_text):
150
+ escaped_text = ''.join(f"&#{ord(char)};" if char not in ('\n', '\r') else '<br>' for char in unsafe_text)
151
+ return escaped_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
153
 
154
  def escape_html(unsafe_text):