nishantgaurav23 commited on
Commit
5f96986
1 Parent(s): 37477f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -347,27 +347,27 @@ class RAGPipeline:
347
 
348
  ### Added on Nov 2, 2024
349
  def postprocess_response(self, response: str) -> str:
350
- """Clean up the generated response"""
351
- try:
352
- # Remove datetime patterns and other unwanted content
353
- response = re.sub(r'\d{4}-\d{2}-\d{2}(?:T|\s)\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?', '', response)
354
- response = re.sub(r'User \d+:.*?(?=User \d+:|$)', '', response)
355
- response = re.sub(r'\d{2}:\d{2}(?::\d{2})?(?:\s?(?:AM|PM))?', '', response)
356
- response = re.sub(r'\d{1,2}[-/]\d{1,2}[-/]\d{2,4}', '', response)
357
- response = re.sub(r'(?m)^User \d+:', '', response)
358
-
359
- # Clean up spacing but preserve intentional paragraph breaks
360
- # Replace multiple newlines with two newlines (one paragraph break)
361
- response = re.sub(r'\n\s*\n\s*\n+', '\n\n', response)
362
- # Replace multiple spaces with single space
363
- response = re.sub(r' +', ' ', response)
364
- # Clean up beginning/end
365
- response = response.strip()
366
-
367
- return response
368
- except Exception as e:
369
- logging.error(f"Error in postprocess_response: {str(e)}")
370
- return response
371
 
372
  def process_query(self, query: str, placeholder) -> str:
373
  try:
 
347
 
348
  ### Added on Nov 2, 2024
349
  def postprocess_response(self, response: str) -> str:
350
+ """Clean up the generated response"""
351
+ try:
352
+ # Remove datetime patterns and other unwanted content
353
+ response = re.sub(r'\d{4}-\d{2}-\d{2}(?:T|\s)\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?', '', response)
354
+ response = re.sub(r'User \d+:.*?(?=User \d+:|$)', '', response)
355
+ response = re.sub(r'\d{2}:\d{2}(?::\d{2})?(?:\s?(?:AM|PM))?', '', response)
356
+ response = re.sub(r'\d{1,2}[-/]\d{1,2}[-/]\d{2,4}', '', response)
357
+ response = re.sub(r'(?m)^User \d+:', '', response)
358
+
359
+ # Clean up spacing but preserve intentional paragraph breaks
360
+ # Replace multiple newlines with two newlines (one paragraph break)
361
+ response = re.sub(r'\n\s*\n\s*\n+', '\n\n', response)
362
+ # Replace multiple spaces with single space
363
+ response = re.sub(r' +', ' ', response)
364
+ # Clean up beginning/end
365
+ response = response.strip()
366
+
367
+ return response
368
+ except Exception as e:
369
+ logging.error(f"Error in postprocess_response: {str(e)}")
370
+ return response
371
 
372
  def process_query(self, query: str, placeholder) -> str:
373
  try: