Pijush2023 commited on
Commit
fe10764
·
verified ·
1 Parent(s): df19645

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -585,7 +585,7 @@ def clean_response(response_text):
585
  document_name = "Unknown"
586
  page_number = "Unknown"
587
 
588
- # Remove the entire 'Document(metadata=...' and any mention of it from the response
589
  response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
590
 
591
  # Remove any mention of "Document:" in the response
@@ -594,9 +594,12 @@ def clean_response(response_text):
594
  # Remove any unwanted escape characters like \u and \u00
595
  response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
596
 
597
- # Ensure proper spacing between words and dates
598
- response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text)
599
- response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text)
 
 
 
600
 
601
  # Remove the phrase "Sure! The Responses are as follows:" from the actual content
602
  response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
@@ -604,8 +607,9 @@ def clean_response(response_text):
604
  # Clean up the text by removing extra whitespace
605
  cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
606
 
607
- # Format the final response with bullet points
608
  final_response = f"""
 
609
  • Document name - {document_name}
610
  • Page No - {page_number}
611
  • Response - {cleaned_response}
@@ -618,6 +622,7 @@ def clean_response(response_text):
618
 
619
 
620
 
 
621
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
622
  gpt4o_mini_template_details = f"""
623
  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.
 
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 mention of "Document:" in the response
 
594
  # Remove any unwanted escape characters like \u and \u00
595
  response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
596
 
597
+ # Ensure proper spacing between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
598
+ response_text = re.sub(r'([a-zA-Z])(\d)', r'\1 \2', response_text) # Letter followed by a number
599
+ response_text = re.sub(r'(\d)([a-zA-Z])', r'\1 \2', response_text) # Number followed by a letter
600
+
601
+ # Ensure there are spaces between capital letters and lowercase (e.g., "CognomeBELLAVISTA" becomes "Cognome BELLAVISTA")
602
+ response_text = re.sub(r'([a-z])([A-Z])', r'\1 \2', response_text)
603
 
604
  # Remove the phrase "Sure! The Responses are as follows:" from the actual content
605
  response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
 
607
  # Clean up the text by removing extra whitespace
608
  cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
609
 
610
+ # Format the final response with bullet points and re-add "Sure! The Responses are as follows:"
611
  final_response = f"""
612
+ Sure! The Responses are as follows:
613
  • Document name - {document_name}
614
  • Page No - {page_number}
615
  • Response - {cleaned_response}
 
622
 
623
 
624
 
625
+
626
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
627
  gpt4o_mini_template_details = f"""
628
  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.