POLRAMBORA commited on
Commit
b229b6a
·
verified ·
1 Parent(s): 21504b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -29
app.py CHANGED
@@ -115,46 +115,44 @@ def render_message(history):
115
 
116
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
117
  if user_message:
118
- user_message_html = markdown.markdown(user_message)
 
 
119
  messages_html += f"""
120
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
121
  <img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
122
- <span id="message-content" style='color: white;'>{user_message_html}</span>
123
- </div><br>"""
124
 
125
  if assistant_message:
126
- assistant_message_html = markdown.markdown(assistant_message)
 
 
127
  messages_html += f"""
128
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
129
  <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
130
- <span id="message-content" style='color: white;'>{assistant_message_html}</span>
131
- </div><br>"""
132
-
133
- messages_html += """
134
- </div></div>
135
- <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.3/purify.min.js"></script>
136
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js"></script>
137
- <script>
138
- function escapeHtml(unsafe) {
139
- return unsafe
140
- .replace(/&/g, "&amp;")
141
- .replace(/</g, "&lt;")
142
- .replace(/>/g, "&gt;")
143
- .replace(/"/g, "&quot;")
144
- .replace(/'/g, "&#039;");
145
- }
146
- let message = document.getElementById('message-content').innerHTML;
147
- document.getElementById('message-content').innerHTML = escapeHtml(message);
148
- MathJax.typeset(); // Process math expressions
149
- </script>
150
- """
151
- return messages_html
152
 
 
153
 
154
  js = """
155
- function HTMLClean() {
156
- alert("This page is in-dev stage, expect lots of restarts, the interface is open-sourced (not the backend that is responsible for API Keys)")
157
- }
 
 
 
 
 
 
 
 
 
158
  """
159
  css="""
160
  .chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}
 
115
 
116
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
117
  if user_message:
118
+ user_message_html = markdown.markdown(
119
+ user_message, extensions=["fenced_code", CodeHiliteExtension()]
120
+ )
121
  messages_html += f"""
122
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
123
  <img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
124
+ <span style='color: white;'>{user_message_html}</span>
125
+ </div>"""
126
 
127
  if assistant_message:
128
+ assistant_message_html = markdown.markdown(
129
+ assistant_message, extensions=["fenced_code", CodeHiliteExtension()]
130
+ )
131
  messages_html += f"""
132
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
133
  <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
134
+ <span style='color: white;'>{assistant_message_html}</span>
135
+ </div>
136
+ <script type="text/javascript" id="MathJax-script" async
137
+ src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js">
138
+ </script>
139
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
+ return messages_html
142
 
143
  js = """
144
+ document.addEventListener("DOMContentLoaded", function() {
145
+ MathJax = {
146
+ tex: {
147
+ inlineMath: [['$', '$'], ['\\(', '\\)']],
148
+ displayMath: [['$$', '$$'], ['\\[', '\\]']]
149
+ },
150
+ svg: {
151
+ fontCache: 'global'
152
+ }
153
+ };
154
+ MathJax.typeset(); // Process math expressions globally
155
+ });
156
  """
157
  css="""
158
  .chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}