vsj0702 commited on
Commit
aabc428
·
verified ·
1 Parent(s): e9ec46a
Files changed (1) hide show
  1. chatbot.py +18 -28
chatbot.py CHANGED
@@ -131,18 +131,18 @@ def render_chatbot(code, output, error):
131
  st.markdown(f'<div class="chat-message user-message">{escape(q)}</div>', unsafe_allow_html=True)
132
 
133
  def format_response(txt):
134
- parts = txt.split('```')
135
- result = ''
136
- for j, part in enumerate(parts):
137
- if j % 2 == 1:
138
- lines = part.splitlines()
139
- if lines and lines[0].isalpha():
140
- lines = lines[1:]
141
- code_html = escape("\n".join(lines))
142
- result += f'<pre><code>{code_html}</code></pre>'
143
- else:
144
- result += escape(part)
145
- return result
146
 
147
  formatted = format_response(a)
148
  st.markdown(f'<div class="chat-message bot-message">{formatted}</div>', unsafe_allow_html=True)
@@ -169,19 +169,9 @@ def render_chatbot(code, output, error):
169
  st.session_state.chat_display_count += 5
170
  st.rerun()
171
 
172
- st.markdown("""
173
- <script>
174
- const c = window.parent.document.querySelector('.chat-container');
175
- if (c) c.scrollTop = c.scrollHeight;
176
- </script>
177
-
178
- <script>
179
- document.querySelectorAll('audio').forEach(audio => {
180
- audio.addEventListener('play', function () {
181
- document.querySelectorAll('audio').forEach(a => {
182
- if (a !== this) a.pause();
183
- });
184
- });
185
- });
186
- </script>
187
- """, unsafe_allow_html=True)
 
131
  st.markdown(f'<div class="chat-message user-message">{escape(q)}</div>', unsafe_allow_html=True)
132
 
133
  def format_response(txt):
134
+ parts = txt.split('```')
135
+ result = ''
136
+ for j, part in enumerate(parts):
137
+ if j % 2 == 1:
138
+ lines = part.splitlines()
139
+ if lines and lines[0].isalpha():
140
+ lines = lines[1:]
141
+ code_html = escape("\n".join(lines))
142
+ result += f'<pre><code>{code_html}</code></pre>'
143
+ else:
144
+ result += escape(part)
145
+ return result
146
 
147
  formatted = format_response(a)
148
  st.markdown(f'<div class="chat-message bot-message">{formatted}</div>', unsafe_allow_html=True)
 
169
  st.session_state.chat_display_count += 5
170
  st.rerun()
171
 
172
+ st.markdown("""
173
+ <script>
174
+ const c = window.parent.document.querySelector('.chat-container');
175
+ if (c) c.scrollTop = c.scrollHeight;
176
+ </script>
177
+ """, unsafe_allow_html=True)