POLRAMBORA commited on
Commit
72ece84
·
verified ·
1 Parent(s): 4b21cf5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -103,9 +103,9 @@ def respond(message, api_key, max_tokens, top_p, temperature):
103
  line = line[5:].strip()
104
  if line:
105
  chunk = json.loads(line)
106
- chunk_message = chunk.get("chunk", {}).get("content", "")
107
  assistant_reply += chunk_message
108
- yield assistant_reply
109
  except json.JSONDecodeError:
110
  pass
111
 
@@ -117,13 +117,12 @@ def respond(message, api_key, max_tokens, top_p, temperature):
117
 
118
 
119
 
120
-
121
  def render_message(history):
122
  messages_html = """
123
  <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;">
124
  <div id="messages" style="display: block; margin-bottom: 10px;">"""
125
 
126
- seen_messages = set() # Track rendered messages to avoid duplication
127
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
128
  if user_message and user_message not in seen_messages:
129
  seen_messages.add(user_message)
@@ -136,15 +135,16 @@ def render_message(history):
136
 
137
  if assistant_message and assistant_message not in seen_messages:
138
  seen_messages.add(assistant_message)
 
139
  messages_html += f"""
140
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
141
  <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
142
- <span style='color: white;'>{escape_html(assistant_message)}</span>
143
  </div>"""
144
 
145
  messages_html += "</div></div>"
146
  return messages_html
147
-
148
  def escape_html(unsafe_text):
149
  return (
150
  unsafe_text.replace("&", "&amp;")
 
103
  line = line[5:].strip()
104
  if line:
105
  chunk = json.loads(line)
106
+ chunk_message = chunk.get("delta", {}).get("content", "")
107
  assistant_reply += chunk_message
108
+ yield assistant_reply # Stream the response incrementally
109
  except json.JSONDecodeError:
110
  pass
111
 
 
117
 
118
 
119
 
 
120
  def render_message(history):
121
  messages_html = """
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
  for user_message, assistant_message, user_profile, assistant_profile, user_pic, assistant_pic in history:
127
  if user_message and user_message not in seen_messages:
128
  seen_messages.add(user_message)
 
135
 
136
  if assistant_message and assistant_message not in seen_messages:
137
  seen_messages.add(assistant_message)
138
+ assistant_message_html = markdown.markdown(escape_html(assistant_message), extensions=["fenced_code", "codehilite"])
139
  messages_html += f"""
140
  <div style='display: flex; align-items: center; margin-bottom: 10px;'>
141
  <img src='{assistant_pic}' style='width: 40px; height: 40px; border-radius: 50%; margin-right: 10px;'>
142
+ <span style='color: white;'>{assistant_message_html}</span>
143
  </div>"""
144
 
145
  messages_html += "</div></div>"
146
  return messages_html
147
+
148
  def escape_html(unsafe_text):
149
  return (
150
  unsafe_text.replace("&", "&amp;")