Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -604,8 +604,6 @@ import re
|
|
604 |
|
605 |
# return final_response
|
606 |
|
607 |
-
import re
|
608 |
-
|
609 |
def clean_response(response_text):
|
610 |
# Remove system and user tags
|
611 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
@@ -624,9 +622,9 @@ def clean_response(response_text):
|
|
624 |
|
625 |
# Remove the entire 'Document(metadata=...' and any mention of it from the response
|
626 |
response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
|
627 |
-
|
628 |
-
#
|
629 |
-
|
630 |
|
631 |
# Remove any unwanted escape characters like \u and \u00
|
632 |
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
@@ -638,24 +636,21 @@ def clean_response(response_text):
|
|
638 |
# Remove the phrase "Sure! The Responses are as follows:" from the actual content
|
639 |
response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
|
640 |
|
641 |
-
# Extract and limit to top 5 results
|
642 |
-
result_lines = response_text.splitlines()[:5]
|
643 |
-
top_5_results = "\n".join(result_lines)
|
644 |
-
|
645 |
# Clean up the text by removing extra whitespace
|
646 |
cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
|
647 |
|
648 |
-
# Format the final response with bullet points
|
649 |
final_response = f"""
|
650 |
-
|
651 |
-
|
|
|
|
|
|
|
|
|
|
|
652 |
|
653 |
-
|
654 |
-
{top_5_results}
|
655 |
|
656 |
-
Risultato effettivo:
|
657 |
-
{cleaned_response}
|
658 |
-
"""
|
659 |
|
660 |
|
661 |
|
|
|
604 |
|
605 |
# return final_response
|
606 |
|
|
|
|
|
607 |
def clean_response(response_text):
|
608 |
# Remove system and user tags
|
609 |
response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
|
|
|
622 |
|
623 |
# Remove the entire 'Document(metadata=...' and any mention of it from the response
|
624 |
response_text = re.sub(r'Document\(metadata=\{.*?\},page_content=', '', response_text, flags=re.DOTALL)
|
625 |
+
|
626 |
+
# Extract top 5 fetched results (based on some identifier you have)
|
627 |
+
top_results = response_text.split('\n')[:5] # Assuming top 5 results are first 5 lines of content
|
628 |
|
629 |
# Remove any unwanted escape characters like \u and \u00
|
630 |
response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text)
|
|
|
636 |
# Remove the phrase "Sure! The Responses are as follows:" from the actual content
|
637 |
response_text = re.sub(r'Sure! The Responses are as follows:', '', response_text).strip()
|
638 |
|
|
|
|
|
|
|
|
|
639 |
# Clean up the text by removing extra whitespace
|
640 |
cleaned_response = re.sub(r'\s+', ' ', response_text).strip()
|
641 |
|
642 |
+
# Format the final response with bullet points
|
643 |
final_response = f"""
|
644 |
+
Sure! Here is the response for your Query:
|
645 |
+
• Document name - {document_name}
|
646 |
+
• Page No - {page_number}
|
647 |
+
• Top 5 Fetched Results:
|
648 |
+
{''.join([f'{i+1}. {result.strip()}\n' for i, result in enumerate(top_results)])}
|
649 |
+
• Actual Response: {cleaned_response}
|
650 |
+
"""
|
651 |
|
652 |
+
return final_response
|
|
|
653 |
|
|
|
|
|
|
|
654 |
|
655 |
|
656 |
|