Wajahat698 commited on
Commit
4858aec
·
verified ·
1 Parent(s): be9d07a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -2107,7 +2107,20 @@ def clean_and_format_markdown(text: str) -> str:
2107
  return text
2108
 
2109
 
 
 
 
 
 
 
 
2110
 
 
 
 
 
 
 
2111
 
2112
  prompt = st.chat_input("")
2113
  global combined_text
@@ -2260,7 +2273,7 @@ def handle_prompt(prompt):
2260
  })
2261
  full_response = output["output"]
2262
 
2263
- #cleaned_text = clean_and_format_markdown(full_response)
2264
 
2265
  # Use Markdown with a styled div to ensure proper word wrapping
2266
 
@@ -2271,11 +2284,11 @@ def handle_prompt(prompt):
2271
  trust_tip, suggestion = get_trust_tip_and_suggestion()
2272
 
2273
  # Combine the response text with Trust Tip and Suggestion
2274
- combined_text = f"{full_response}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
2275
 
2276
  else:
2277
  # If already present, just use the full response
2278
- combined_text = full_response
2279
  with response_placeholder:
2280
  with st.chat_message("assistant"):
2281
  st.markdown(combined_text, unsafe_allow_html=True)
 
2107
  return text
2108
 
2109
 
2110
+ def minimal_clean_text(text):
2111
+ # Normalize Unicode to ensure a consistent form
2112
+ text = unicodedata.normalize('NFKC', text)
2113
+
2114
+ # Remove zero-width and invisible characters
2115
+ # (e.g., \u200B, \uFEFF, \u200C, \u200D)
2116
+ text = re.sub(r'[\u200B\uFEFF\u200C\u200D]', '', text)
2117
 
2118
+ # Remove control characters (ASCII control chars and DEL)
2119
+ text = re.sub(r'[\x00-\x1F\x7F-\x9F]', '', text)
2120
+
2121
+ # Do not alter spacing, punctuation, or other formatting
2122
+
2123
+ return text
2124
 
2125
  prompt = st.chat_input("")
2126
  global combined_text
 
2273
  })
2274
  full_response = output["output"]
2275
 
2276
+ cleaned_text = minimal_clean_text(full_response)
2277
 
2278
  # Use Markdown with a styled div to ensure proper word wrapping
2279
 
 
2284
  trust_tip, suggestion = get_trust_tip_and_suggestion()
2285
 
2286
  # Combine the response text with Trust Tip and Suggestion
2287
+ combined_text = f"{cleaned_text}\n\n---\n\n**Trust Tip**: {trust_tip}\n\n**Suggestion**: {suggestion}"
2288
 
2289
  else:
2290
  # If already present, just use the full response
2291
+ combined_text = cleaned_text
2292
  with response_placeholder:
2293
  with st.chat_message("assistant"):
2294
  st.markdown(combined_text, unsafe_allow_html=True)