Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import markdown
|
|
6 |
from markdown.extensions.codehilite import CodeHiliteExtension
|
7 |
import markdown.extensions.fenced_code
|
8 |
import bleach
|
|
|
9 |
|
10 |
API_URL = "https://host.palple.polrambora.com/pmsq"
|
11 |
|
@@ -138,13 +139,19 @@ def render_message(history):
|
|
138 |
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
139 |
if user_message and ("user", user_message) not in seen_messages:
|
140 |
seen_messages.add(("user", user_message))
|
|
|
141 |
user_message_html = markdown.markdown(
|
142 |
user_message,
|
143 |
-
extensions=["fenced_code", "codehilite"]
|
|
|
144 |
)
|
|
|
145 |
user_message_html = bleach.clean(
|
146 |
user_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
147 |
)
|
|
|
|
|
|
|
148 |
messages_html += f"""
|
149 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
150 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
@@ -153,13 +160,19 @@ def render_message(history):
|
|
153 |
|
154 |
if assistant_message and ("assistant", assistant_message) not in seen_messages:
|
155 |
seen_messages.add(("assistant", assistant_message))
|
|
|
156 |
assistant_message_html = markdown.markdown(
|
157 |
-
assistant_message,
|
158 |
-
extensions=["fenced_code", "codehilite"]
|
|
|
159 |
)
|
|
|
160 |
assistant_message_html = bleach.clean(
|
161 |
assistant_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
162 |
)
|
|
|
|
|
|
|
163 |
messages_html += f"""
|
164 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
165 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
@@ -169,7 +182,6 @@ def render_message(history):
|
|
169 |
messages_html += "</div></div>"
|
170 |
return messages_html
|
171 |
|
172 |
-
|
173 |
def escape_html(unsafe_text):
|
174 |
escaped_text = ''.join(f"&#{ord(char)};" if char not in ('\n', '\r') else '<br>' for char in unsafe_text)
|
175 |
return escaped_text
|
|
|
6 |
from markdown.extensions.codehilite import CodeHiliteExtension
|
7 |
import markdown.extensions.fenced_code
|
8 |
import bleach
|
9 |
+
from html import escape
|
10 |
|
11 |
API_URL = "https://host.palple.polrambora.com/pmsq"
|
12 |
|
|
|
139 |
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
140 |
if user_message and ("user", user_message) not in seen_messages:
|
141 |
seen_messages.add(("user", user_message))
|
142 |
+
|
143 |
user_message_html = markdown.markdown(
|
144 |
user_message,
|
145 |
+
extensions=["fenced_code", "codehilite"],
|
146 |
+
output_format="html5"
|
147 |
)
|
148 |
+
|
149 |
user_message_html = bleach.clean(
|
150 |
user_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
151 |
)
|
152 |
+
|
153 |
+
user_message_html = escape(user_message_html)
|
154 |
+
|
155 |
messages_html += f"""
|
156 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
157 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
|
|
160 |
|
161 |
if assistant_message and ("assistant", assistant_message) not in seen_messages:
|
162 |
seen_messages.add(("assistant", assistant_message))
|
163 |
+
|
164 |
assistant_message_html = markdown.markdown(
|
165 |
+
assistant_message,
|
166 |
+
extensions=["fenced_code", "codehilite"],
|
167 |
+
output_format="html5"
|
168 |
)
|
169 |
+
|
170 |
assistant_message_html = bleach.clean(
|
171 |
assistant_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
172 |
)
|
173 |
+
|
174 |
+
assistant_message_html = escape(assistant_message_html)
|
175 |
+
|
176 |
messages_html += f"""
|
177 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
178 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
|
|
182 |
messages_html += "</div></div>"
|
183 |
return messages_html
|
184 |
|
|
|
185 |
def escape_html(unsafe_text):
|
186 |
escaped_text = ''.join(f"&#{ord(char)};" if char not in ('\n', '\r') else '<br>' for char in unsafe_text)
|
187 |
return escaped_text
|