Nyanfa commited on
Commit
eb20940
·
verified ·
1 Parent(s): d2e11f2

Minor adjustments

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -100,7 +100,12 @@ def normalize_code_block(match):
100
  .replace("\\<", "<")\
101
  .replace("\\>", ">")
102
 
 
 
 
 
103
  code_block_pattern = r"(```.*?```)"
 
104
 
105
  def display_messages():
106
  for i, message in enumerate(st.session_state.messages):
@@ -111,6 +116,8 @@ def display_messages():
111
  if "```" in shown_message:
112
  # Replace " \n" with "\n" within code blocks
113
  shown_message = re.sub(code_block_pattern, normalize_code_block, shown_message, flags=re.DOTALL)
 
 
114
  st.markdown(shown_message)
115
 
116
  col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
@@ -300,7 +307,7 @@ with st.sidebar:
300
  st.warning("Please enter a valid Project ID.")
301
 
302
  # After Stop generating
303
- if "is_streaming" in st.session_state and st.session_state.is_streaming:
304
  st.session_state.messages.append({"role": "assistant", "content": st.session_state.response})
305
  st.session_state.is_error = False
306
  st.session_state.is_streaming = False
@@ -311,7 +318,7 @@ if "is_streaming" in st.session_state and st.session_state.is_streaming:
311
  display_messages()
312
 
313
  # After Retry
314
- if "retry_flag" in st.session_state and st.session_state.retry_flag == True:
315
  if len(st.session_state.messages) > 0:
316
  messages = st.session_state.messages.copy()
317
  response = get_ai_response(messages)
 
100
  .replace("\\<", "<")\
101
  .replace("\\>", ">")
102
 
103
+ def normalize_inline(match):
104
+ return match.group(0).replace("\\<", "<")\
105
+ .replace("\\>", ">")
106
+
107
  code_block_pattern = r"(```.*?```)"
108
+ inline_pattern = r"`([^`\n]+?)`"
109
 
110
  def display_messages():
111
  for i, message in enumerate(st.session_state.messages):
 
116
  if "```" in shown_message:
117
  # Replace " \n" with "\n" within code blocks
118
  shown_message = re.sub(code_block_pattern, normalize_code_block, shown_message, flags=re.DOTALL)
119
+ if "`" in shown_message:
120
+ shown_message = re.sub(inline_pattern, normalize_inline, shown_message)
121
  st.markdown(shown_message)
122
 
123
  col1, col2, col3, col4 = st.columns([1, 1, 1, 1])
 
307
  st.warning("Please enter a valid Project ID.")
308
 
309
  # After Stop generating
310
+ if st.session_state.get("is_streaming"):
311
  st.session_state.messages.append({"role": "assistant", "content": st.session_state.response})
312
  st.session_state.is_error = False
313
  st.session_state.is_streaming = False
 
318
  display_messages()
319
 
320
  # After Retry
321
+ if st.session_state.get("retry_flag"):
322
  if len(st.session_state.messages) > 0:
323
  messages = st.session_state.messages.copy()
324
  response = get_ai_response(messages)