Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -122,28 +122,12 @@ 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 |
-
allowed_tags = [
|
128 |
-
'p', 'strong', 'em', 'ul', 'ol', 'li', 'a', 'code', 'pre', 'br', 'blockquote', 'hr',
|
129 |
-
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'img'
|
130 |
-
]
|
131 |
-
allowed_attributes = {
|
132 |
-
'*': ['class', 'style'],
|
133 |
-
'a': ['href', 'title'],
|
134 |
-
'img': ['src', 'alt', 'title', 'width', 'height']
|
135 |
-
}
|
136 |
|
137 |
for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
|
138 |
if user_message and ("user", user_message) not in seen_messages:
|
139 |
seen_messages.add(("user", user_message))
|
140 |
-
user_message_html = markdown.markdown(
|
141 |
-
user_message,
|
142 |
-
extensions=["fenced_code", "codehilite"]
|
143 |
-
)
|
144 |
-
user_message_html = bleach.clean(
|
145 |
-
user_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
146 |
-
)
|
147 |
messages_html += f"""
|
148 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
149 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
@@ -152,13 +136,7 @@ def render_message(history):
|
|
152 |
|
153 |
if assistant_message and ("assistant", assistant_message) not in seen_messages:
|
154 |
seen_messages.add(("assistant", assistant_message))
|
155 |
-
assistant_message_html = markdown.markdown(
|
156 |
-
assistant_message,
|
157 |
-
extensions=["fenced_code", "codehilite"]
|
158 |
-
)
|
159 |
-
assistant_message_html = bleach.clean(
|
160 |
-
assistant_message_html, tags=allowed_tags, attributes=allowed_attributes, strip=True
|
161 |
-
)
|
162 |
messages_html += f"""
|
163 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
164 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
@@ -174,7 +152,6 @@ 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
|
176 |
|
177 |
-
|
178 |
css="""
|
179 |
.chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}
|
180 |
"""
|
|
|
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() # Track (role, message) pairs to avoid duplicates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
user_message_html = markdown.markdown(user_message, extensions=["fenced_code", "codehilite"])
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
messages_html += f"""
|
132 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
133 |
<img src='{user_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
|
|
136 |
|
137 |
if assistant_message and ("assistant", assistant_message) not in seen_messages:
|
138 |
seen_messages.add(("assistant", assistant_message))
|
139 |
+
assistant_message_html = markdown.markdown(assistant_message, extensions=["fenced_code", "codehilite"])
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
messages_html += f"""
|
141 |
<div style='display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 10px;'>
|
142 |
<img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-bottom: 5px;'>
|
|
|
152 |
escaped_text = ''.join(f"&#{ord(char)};" if char not in ('\n', '\r') else '<br>' for char in unsafe_text)
|
153 |
return escaped_text
|
154 |
|
|
|
155 |
css="""
|
156 |
.chatbox {height: 400px; overflow: auto; border: 1px solid #262626; padding: 10px; background-color: #171717; display: flex; flex-direction: column-reverse;}
|
157 |
"""
|