Spaces:
Build error
Build error
Update app.py
Browse files102 unmodified lines1031041051061061071081081091101115 unmodified lines1171181191201201211221231241261251261271286 unmodified lines135136137138139140141142142143144145146147147148149150102 unmodified lines line = line[5:].strip() if line: chunk = json.loads(line) chunk_message = chunk.get("chunk", {}).get("content", "") chunk_message = chunk.get("delta", {}).get("content", "") assistant_reply += chunk_message yield assistant_reply yield assistant_reply # Stream the response incrementally except json.JSONDecodeError: pass
5 unmodified lines
def render_message(history): messages_html = """ <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;"> <div id="messages" style="display: block; margin-bottom: 10px;">"""
seen_messages = set() # Track rendered messages to avoid duplication seen_messages = set() for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history: if user_message and user_message not in seen_messages: seen_messages.add(user_message)6 unmodified lines
if assistant_message and assistant_message not in seen_messages: seen_messages.add(assistant_message) assistant_message_html = markdown.markdown(escape_html(assistant_message), extensions=["fenced_code", "codehilite"]) messages_html += f""" <div style='display: flex; align-items: center; margin-bottom: 10px;'> <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'> <span style='color: white;'>{escape_html(assistant_message)}</span> <span style='color: white;'>{assistant_message_html}</span> </div>"""
messages_html += "</div></div>" return messages_html
def escape_html(unsafe_text): return ( unsafe_text.replace("&", "&")app.py+6-6