Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
|
|
|
|
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
|
123 |
-
</div
|
124 |
|
125 |
if assistant_message:
|
126 |
-
assistant_message_html = markdown.markdown(
|
|
|
|
|
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
|
131 |
-
</div
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
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, "&")
|
141 |
-
.replace(/</g, "<")
|
142 |
-
.replace(/>/g, ">")
|
143 |
-
.replace(/"/g, """)
|
144 |
-
.replace(/'/g, "'");
|
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
|
156 |
-
|
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;}
|