Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -577,35 +577,28 @@ 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+)\}", 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 mention of "Document:" in the response
|
592 |
-
response_text = re.sub(r'- Document:.*', '', response_text)
|
593 |
|
594 |
# Remove any unwanted escape characters like \u and \u00
|
595 |
-
|
596 |
|
597 |
# Ensure proper spacing between words and dates (e.g., "born04/04/1963" becomes "born 04/04/1963")
|
598 |
-
|
599 |
-
|
600 |
|
601 |
# Ensure there are spaces between capital letters and lowercase (e.g., "CognomeBELLAVISTA" becomes "Cognome BELLAVISTA")
|
602 |
-
|
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()
|
606 |
|
607 |
# Clean up the text by removing extra whitespace
|
608 |
-
cleaned_response = re.sub(r'\s+', ' ',
|
609 |
|
610 |
# Format the final response with bullet points and re-add "Sure! The Responses are as follows:"
|
611 |
final_response = f"""
|
@@ -623,6 +616,7 @@ Sure! The Responses are as follows:
|
|
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.
|
|
|
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"""
|
|
|
616 |
|
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.
|