Wajahat698 commited on
Commit
e964295
·
verified ·
1 Parent(s): 15dd0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -244,7 +244,15 @@ def search_knowledge_base(query):
244
  except Exception as e:
245
  logger.error(f"Error searching knowledge base: {e}")
246
  return ["Error occurred during knowledge base search"]
247
-
 
 
 
 
 
 
 
 
248
  def google_search(query):
249
  try:
250
  search_client = serpapi.Client(api_key=serper_api_key)
@@ -528,8 +536,7 @@ if prompt :
528
  })
529
  full_response = output["output"]
530
 
531
- cleaned_text = re.sub(r'\s+', ' ', full_response) # Replace multiple spaces or newlines with a single space
532
- cleaned_text = re.sub(r'([a-z])(\d)', r'\1 \2', full_response) # Add a space between letters and numbers if necessary
533
 
534
  # Display the response
535
  if "**Trust Tip**" not in full_response and "**Suggestion**" not in full_response:
 
244
  except Exception as e:
245
  logger.error(f"Error searching knowledge base: {e}")
246
  return ["Error occurred during knowledge base search"]
247
+ def clean_text(text):
248
+ # Remove HTML tags and inline styles/classes
249
+ text = re.sub(r'<span[^>]*>', '', text) # Remove <span> tags with attributes
250
+ text = re.sub(r'</span>', '', text) # Remove closing </span> tags
251
+ text = re.sub(r'<[^>]+>', '', text) # Remove any remaining HTML tags
252
+ text = re.sub(r'\s+', ' ', text) # Replace multiple spaces or newlines with a single space
253
+ text = re.sub(r'([a-z])(\d)', r'\1 \2', text) # Add a space between letters and numbers if necessary
254
+ return text.strip()
255
+
256
  def google_search(query):
257
  try:
258
  search_client = serpapi.Client(api_key=serper_api_key)
 
536
  })
537
  full_response = output["output"]
538
 
539
+ cleaned_text = clean_text(full_response) # Add a space between letters and numbers if necessary
 
540
 
541
  # Display the response
542
  if "**Trust Tip**" not in full_response and "**Suggestion**" not in full_response: