jaelin215 commited on
Commit
b3080b9
1 Parent(s): cb96e5d

Remove incomplete sentence

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -101,6 +101,22 @@ def remove_html_tags(text):
101
  clean_text = clean_text.replace('\n', ' ')
102
  return clean_text
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  # Initialize memory
105
  if "entered_text" not in st.session_state:
106
  st.session_state.entered_text = []
@@ -301,6 +317,7 @@ if user_message:
301
  )
302
 
303
  llm_response = remove_html_tags(llm_response)
 
304
 
305
  if show_question:
306
  llm_reponse_with_quesiton = f"{llm_response}\n\n{question}"
 
101
  clean_text = clean_text.replace('\n', ' ')
102
  return clean_text
103
 
104
+
105
+ def remove_incomplete_sentence(text):
106
+ # Split the text into sentences using punctuation marks as delimiters
107
+ sentences = re.split(r'(?<=[.!?])\s', text)
108
+
109
+ # Check if the last sentence is complete
110
+ last_sentence = sentences[-1]
111
+ if not re.match(r'^\w.*[.!?]$', last_sentence):
112
+ del sentences[-1]
113
+
114
+ # Join the sentences back into a single string
115
+ cleaned_text = ' '.join(sentences)
116
+
117
+ return cleaned_text
118
+
119
+
120
  # Initialize memory
121
  if "entered_text" not in st.session_state:
122
  st.session_state.entered_text = []
 
317
  )
318
 
319
  llm_response = remove_html_tags(llm_response)
320
+ llm_response = remove_incomplete_sentence(llm_response)
321
 
322
  if show_question:
323
  llm_reponse_with_quesiton = f"{llm_response}\n\n{question}"