Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -585,27 +585,26 @@ def clean_response(response_text):
|
|
585 |
document_name = "Unknown"
|
586 |
page_number = "Unknown"
|
587 |
|
588 |
-
# Remove the
|
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 |
-
#
|
595 |
-
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
596 |
|
597 |
-
# Ensure proper spacing
|
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 |
-
#
|
602 |
-
|
603 |
|
604 |
-
#
|
605 |
-
|
|
|
606 |
|
607 |
-
# Create a table format for the document name
|
608 |
final_response = f"""
|
|
|
609 |
<table style="width:100%;border: 1px solid black;border-collapse: collapse;">
|
610 |
<tr>
|
611 |
<th style="border: 1px solid black;padding: 8px;text-align: left;">Document Name</th>
|
@@ -616,7 +615,7 @@ def clean_response(response_text):
|
|
616 |
<td style="border: 1px solid black;padding: 8px;">{page_number}</td>
|
617 |
</tr>
|
618 |
</table>
|
619 |
-
<p>Response
|
620 |
"""
|
621 |
|
622 |
return final_response
|
@@ -630,6 +629,7 @@ def clean_response(response_text):
|
|
630 |
|
631 |
|
632 |
|
|
|
633 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
634 |
gpt4o_mini_template_details = f"""
|
635 |
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 and unnecessary characters from the response
|
589 |
response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
|
|
|
|
|
|
|
590 |
|
591 |
+
# Clean up and extract the relevant response content
|
592 |
+
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text) # Remove any unwanted escape characters
|
593 |
|
594 |
+
# Ensure proper spacing
|
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 |
+
# Strip excess spaces and format the final response content
|
599 |
+
cleaned_response = response_text.strip()
|
600 |
|
601 |
+
# Handle blank or empty responses
|
602 |
+
if not cleaned_response:
|
603 |
+
cleaned_response = "No relevant content found in the document."
|
604 |
|
605 |
+
# Create a table format for the document name, page number, and response
|
606 |
final_response = f"""
|
607 |
+
Here is the response of your Query <br>
|
608 |
<table style="width:100%;border: 1px solid black;border-collapse: collapse;">
|
609 |
<tr>
|
610 |
<th style="border: 1px solid black;padding: 8px;text-align: left;">Document Name</th>
|
|
|
615 |
<td style="border: 1px solid black;padding: 8px;">{page_number}</td>
|
616 |
</tr>
|
617 |
</table>
|
618 |
+
<p><strong>Response:</strong> {cleaned_response}</p>
|
619 |
"""
|
620 |
|
621 |
return final_response
|
|
|
629 |
|
630 |
|
631 |
|
632 |
+
|
633 |
# Define a new template specifically for GPT-4o-mini in VDB Details mode
|
634 |
gpt4o_mini_template_details = f"""
|
635 |
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.
|