Pijush2023 commited on
Commit
5e878d9
·
verified ·
1 Parent(s): 32c9dcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -585,17 +585,19 @@ def clean_response(response_text):
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
@@ -604,7 +606,7 @@ def clean_response(response_text):
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>
@@ -630,6 +632,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 document metadata and other unnecessary parts
589
+ response_text = re.sub(r"Document\(metadata=\{.*?\}\)", '', response_text, flags=re.DOTALL)
590
+
591
+ # Remove unwanted parts like "Nome del documento" and "Numero di pagina"
592
+ response_text = re.sub(r"Nome del documento:.*\n?", '', response_text)
593
+ response_text = re.sub(r"Numero di pagina:.*\n?", '', response_text)
594
 
595
  # Clean up and extract the relevant response content
596
  response_text = re.sub(r'\\u[0-9A-Fa-f]{4}', '', response_text) # Remove any unwanted escape characters
597
 
598
+ # Ensure proper spacing and remove extra text around the "Contenuto effettivo" and "Risposta" parts
599
+ response_text = re.sub(r'Contenuto effettivo: ', '', response_text)
600
+ response_text = re.sub(r'Risposta: ', '', response_text)
 
 
601
  cleaned_response = response_text.strip()
602
 
603
  # Handle blank or empty responses
 
606
 
607
  # Create a table format for the document name, page number, and response
608
  final_response = f"""
609
+ <br>Here is the response of your Query <br>
610
  <table style="width:100%;border: 1px solid black;border-collapse: collapse;">
611
  <tr>
612
  <th style="border: 1px solid black;padding: 8px;text-align: left;">Document Name</th>
 
632
 
633
 
634
 
635
+
636
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
637
  gpt4o_mini_template_details = f"""
638
  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.