vsj0702 commited on
Commit
e9ec46a
·
verified ·
1 Parent(s): dfb52fa

Fixing formater

Browse files
Files changed (1) hide show
  1. chatbot.py +12 -12
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)
 
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)