Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,37 +140,48 @@ def render_message(history):
|
|
| 140 |
</div>
|
| 141 |
</div>
|
| 142 |
|
| 143 |
-
|
| 144 |
-
<script type="text/javascript" id="MathJax-script" async
|
| 145 |
-
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js">
|
| 146 |
-
</script>
|
| 147 |
-
|
| 148 |
-
<!-- Trigger MathJax Typeset -->
|
| 149 |
<script>
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
</script>
|
| 156 |
"""
|
| 157 |
|
| 158 |
return messages_html
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
js = """
|
| 162 |
-
|
| 163 |
-
if (typeof MathJax !== 'undefined') {
|
| 164 |
-
MathJax.typeset();
|
| 165 |
-
}
|
| 166 |
-
}
|
| 167 |
"""
|
| 168 |
|
| 169 |
css="""
|
| 170 |
.chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}
|
| 171 |
"""
|
| 172 |
with gr.Blocks(css=css, js=js) as demo:
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
with gr.Column(visible=True) as auth_view:
|
| 175 |
gr.Markdown("## P-MSQ Authorization")
|
| 176 |
gr.Markdown("P-MSQ is in closed alpha test! The model, api and more are subject to change.")
|
|
@@ -180,6 +191,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
| 180 |
auth_status = gr.Textbox(label="Authorization Status", interactive=False)
|
| 181 |
|
| 182 |
with gr.Column(visible=False) as chat_view:
|
|
|
|
| 183 |
gr.Markdown("## P-MSQ Chat Interface")
|
| 184 |
chatbot_output = gr.HTML(elem_id="chatbox-container")
|
| 185 |
|
|
|
|
| 140 |
</div>
|
| 141 |
</div>
|
| 142 |
|
| 143 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
<script>
|
| 145 |
+
function escapeHtml(unsafe) {
|
| 146 |
+
return unsafe
|
| 147 |
+
.replace(/&/g, "&")
|
| 148 |
+
.replace(/</g, "<")
|
| 149 |
+
.replace(/>/g, ">")
|
| 150 |
+
.replace(/"/g, """)
|
| 151 |
+
.replace(/'/g, "'");
|
| 152 |
}
|
| 153 |
+
let messages = document.querySelectorAll('#message-content');
|
| 154 |
+
messages.forEach((message) => {
|
| 155 |
+
message.innerHTML = DOMPurify.sanitize(message.innerHTML); // Sanitize HTML content
|
| 156 |
+
});
|
| 157 |
+
MathJax.typeset();
|
| 158 |
</script>
|
| 159 |
"""
|
| 160 |
|
| 161 |
return messages_html
|
| 162 |
|
| 163 |
+
def escape_html(unsafe_text):
|
| 164 |
+
return (
|
| 165 |
+
unsafe_text.replace("&", "&")
|
| 166 |
+
.replace("<", "<")
|
| 167 |
+
.replace(">", ">")
|
| 168 |
+
.replace('"', """)
|
| 169 |
+
.replace("'", "'")
|
| 170 |
+
)
|
| 171 |
js = """
|
| 172 |
+
console.log("hello")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
"""
|
| 174 |
|
| 175 |
css="""
|
| 176 |
.chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}
|
| 177 |
"""
|
| 178 |
with gr.Blocks(css=css, js=js) as demo:
|
| 179 |
+
gr.HTML("""
|
| 180 |
+
<script type="text/javascript" id="MathJax-script" async
|
| 181 |
+
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js">
|
| 182 |
+
</script>
|
| 183 |
+
""")
|
| 184 |
+
|
| 185 |
with gr.Column(visible=True) as auth_view:
|
| 186 |
gr.Markdown("## P-MSQ Authorization")
|
| 187 |
gr.Markdown("P-MSQ is in closed alpha test! The model, api and more are subject to change.")
|
|
|
|
| 191 |
auth_status = gr.Textbox(label="Authorization Status", interactive=False)
|
| 192 |
|
| 193 |
with gr.Column(visible=False) as chat_view:
|
| 194 |
+
|
| 195 |
gr.Markdown("## P-MSQ Chat Interface")
|
| 196 |
chatbot_output = gr.HTML(elem_id="chatbox-container")
|
| 197 |
|