Pijush2023 commited on
Commit
0df7f00
·
verified ·
1 Parent(s): 0c87983

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -577,30 +577,31 @@ def clean_response(response_text):
577
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
578
 
579
  # Extract the document name and page number
580
- document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\},page_content='(.*?)'", response_text)
581
  if document_match:
582
  document_name = document_match.group(1).split('/')[-1] # Get the document name
583
  page_number = document_match.group(2) # Get the page number
584
- page_content = document_match.group(3) # Get the actual page content
585
  else:
586
  document_name = "Unknown"
587
  page_number = "Unknown"
588
- page_content = "No content available"
 
 
589
 
590
  # Remove any unwanted escape characters like \u and \u00
591
- page_content = re.sub(r'\\u[0-9A-Fa-f]{4}', '', page_content)
592
 
593
- # Ensure proper spacing between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
594
- page_content = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', page_content) # Letter followed by a number
595
- page_content = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', page_content) # Number followed by a letter
596
 
597
- # Ensure there are spaces between capital letters and lowercase (e.g., "CognomeBELLAVISTA" becomes "Cognome BELLAVISTA")
598
- page_content = re.sub(r'([a-z])([A-Z])', r'\1 \2', page_content)
599
 
600
  # Clean up the text by removing extra whitespace
601
- cleaned_response = re.sub(r'\s+', ' ', page_content).strip()
602
 
603
- # Format the final response with bullet points and re-add "Sure! The Responses are as follows:"
604
  final_response = f"""
605
  Sure! The Responses are as follows:
606
  • Document name - {document_name}
@@ -617,6 +618,7 @@ Sure! The Responses are as follows:
617
 
618
 
619
 
 
620
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
621
  gpt4o_mini_template_details = f"""
622
  As a highly specialized assistant, I provide precise, detailed, and informative responses. On this bright day of {current_date}, I'm equipped to assist with all your queries about Birmingham, Alabama, offering detailed insights tailored to your needs.
 
577
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
578
 
579
  # Extract the document name and page number
580
+ document_match = re.search(r"Document\(metadata=\{'source':'(.+?)','page':(\d+)\}", response_text)
581
  if document_match:
582
  document_name = document_match.group(1).split('/')[-1] # Get the document name
583
  page_number = document_match.group(2) # Get the page number
 
584
  else:
585
  document_name = "Unknown"
586
  page_number = "Unknown"
587
+
588
+ # Remove the 'Document(metadata=...' part and keep only the page content
589
+ response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
590
 
591
  # Remove any unwanted escape characters like \u and \u00
592
+ response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
593
 
594
+ # Ensure proper spacing between words and dates
595
+ response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
596
+ response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
597
 
598
+ # Remove the phrase "Sure! The Responses are as follows:" from the actual content
599
+ response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
600
 
601
  # Clean up the text by removing extra whitespace
602
+ cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
603
 
604
+ # Format the final response with bullet points
605
  final_response = f"""
606
  Sure! The Responses are as follows:
607
  • Document name - {document_name}
 
618
 
619
 
620
 
621
+
622
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
623
  gpt4o_mini_template_details = f"""
624
  As a highly specialized assistant, I provide precise, detailed, and informative responses. On this bright day of {current_date}, I'm equipped to assist with all your queries about Birmingham, Alabama, offering detailed insights tailored to your needs.