Spaces:
Build error
Build error
Update app.py
Browse files102 unmodified lines1031041051061071081091101115 unmodified lines1171181191201211221231241251261271281296 unmodified lines136137138139140141142143144145146147148149150102 unmodified linesline = line[5:].strip()if line:chunk = json.loads(line)chunk_message = chunk.get("chunk", {}).get("content", "")assistant_reply += chunk_messageyield assistant_replyexcept json.JSONDecodeError:pass5 unmodified linesdef 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 duplicationfor 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 linesif assistant_message and assistant_message not in seen_messages:seen_messages.add(assistant_message)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></div>"""messages_html += "</div></div>"return messages_htmldef escape_html(unsafe_text):return (unsafe_text.replace("&", "&")102 unmodified lines1031041051061071081091101115 unmodified lines1171181191201211221231241251261271286 unmodified lines135136137138139140141142143144145146147148149150102 unmodified linesline = line[5:].strip()if line:chunk = json.loads(line)chunk_message = chunk.get("delta", {}).get("content", "")assistant_reply += chunk_messageyield assistant_reply # Stream the response incrementallyexcept json.JSONDecodeError:pass5 unmodified linesdef 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()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 linesif 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;'>{assistant_message_html}</span></div>"""messages_html += "</div></div>"return messages_htmldef escape_html(unsafe_text):return (unsafe_text.replace("&", "&")
app.py+6-6