CCockrum commited on
Commit
5fb66c1
·
verified ·
1 Parent(s): 677d102

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -249,13 +249,16 @@ for i, message in enumerate(st.session_state.chat_history):
249
  if message["role"] == "user":
250
  st.markdown(f"<div class='user-msg'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
251
  else:
252
- speak_button = f"""
253
- <button onclick="speakText(`{message['content'].replace('`', '\'').replace('"', '\'')}`)" class="speak-button">
254
- 🔊 Speak
255
- </button>
256
- """
257
  st.markdown(
258
- f"<div class='assistant-msg'><strong>HAL:</strong> {message['content']} {speak_button}</div>",
 
 
 
 
 
 
259
  unsafe_allow_html=True
260
  )
261
  st.markdown("</div>", unsafe_allow_html=True)
 
249
  if message["role"] == "user":
250
  st.markdown(f"<div class='user-msg'><strong>You:</strong> {message['content']}</div>", unsafe_allow_html=True)
251
  else:
252
+ # Fix: Use JavaScript data attribute instead of trying to escape in f-string
253
+ content_for_id = f"msg-{i}"
 
 
 
254
  st.markdown(
255
+ f"""<div class='assistant-msg'>
256
+ <strong>HAL:</strong> {message['content']}
257
+ <button onclick="speakText(document.getElementById('{content_for_id}').textContent)" class="speak-button">
258
+ 🔊 Speak
259
+ </button>
260
+ <span id="{content_for_id}" style="display:none">{message['content']}</span>
261
+ </div>""",
262
  unsafe_allow_html=True
263
  )
264
  st.markdown("</div>", unsafe_allow_html=True)