Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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+)\}
|
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 |
-
|
|
|
|
|
589 |
|
590 |
# Remove any unwanted escape characters like \u and \u00
|
591 |
-
|
592 |
|
593 |
-
# Ensure proper spacing between words and dates
|
594 |
-
|
595 |
-
|
596 |
|
597 |
-
#
|
598 |
-
|
599 |
|
600 |
# Clean up the text by removing extra whitespace
|
601 |
-
cleaned_response = re.sub(r'\s+', ' ',
|
602 |
|
603 |
-
# Format the final response with bullet points
|
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.
|