Pijush2023 commited on
Commit
e283093
·
verified ·
1 Parent(s): 7941ba5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -43
app.py CHANGED
@@ -532,17 +532,20 @@ import re
532
  # return final_response
533
 
534
 
 
 
535
  def clean_response(response_text):
536
  # Remove system and user tags
537
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
538
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
539
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
540
 
541
- # Extract the document name and page number
542
- document_match = re.search(r"(\d{6,})_(\d{12,})_V\d+\.pdf,page:(\d+)", response_text)
 
543
  if document_match:
544
- document_name = document_match.group(0).split(',')[0] # Get the document name (before ',page')
545
- page_number = document_match.group(3) # Get the page number
546
  else:
547
  document_name = "Unknown"
548
  page_number = "Unknown"
@@ -576,6 +579,7 @@ Sure! Here is the response for your Query:
576
 
577
  return final_response
578
 
 
579
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
580
  gpt4o_mini_template_details = f"""
581
  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.
@@ -1499,42 +1503,7 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date=cur
1499
  # return prompt[0] if prompt else current_text
1500
 
1501
 
1502
- import pandas as pd
1503
 
1504
- # Create a function to extract top 3 responses with document name, page number, and confidence level
1505
- def extract_top_responses(response_text):
1506
- # Assuming that the response contains document name, page number, and confidence levels in some format
1507
- # You can adjust the regex or string manipulation based on the actual response format
1508
-
1509
- # Placeholder for document details
1510
- document_name = "Unknown"
1511
- page_number = "Unknown"
1512
-
1513
- # Assuming we have the top 3 responses in the response text
1514
- responses = re.findall(r'Response: (.+?)(?=Confidence:)', response_text)
1515
- confidences = re.findall(r'Confidence: (\d+\.\d+)', response_text)
1516
-
1517
- # Create a DataFrame with top 3 responses based on confidence level
1518
- data = {
1519
- "Document Name": [document_name] * len(confidences[:3]),
1520
- "Page Number": [page_number] * len(confidences[:3]),
1521
- "Top Responses": responses[:3]
1522
- }
1523
- df = pd.DataFrame(data)
1524
-
1525
- return df
1526
-
1527
- # Add function to generate and update the table dynamically
1528
- def update_table_based_on_phi_response(history):
1529
- if not history:
1530
- return pd.DataFrame() # Return an empty DataFrame if no history
1531
-
1532
- response = history[-1][1]
1533
- if response:
1534
- top_responses_df = extract_top_responses(response)
1535
- return top_responses_df
1536
- else:
1537
- return pd.DataFrame()
1538
 
1539
 
1540
 
@@ -1640,10 +1609,7 @@ with gr.Blocks(theme='gradio/soft') as demo:
1640
  # refresh_button = gr.Button("Refresh Images")
1641
  # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1642
 
1643
- with gr.Column():
1644
- # Add the table to display the top 3 responses based on confidence level
1645
- response_table = gr.Dataframe(headers=["Document Name", "Page Number", "Top Responses"], interactive=False, show_label=False)
1646
- # response_table.render()
1647
 
1648
 
1649
 
 
532
  # return final_response
533
 
534
 
535
+ import re
536
+
537
  def clean_response(response_text):
538
  # Remove system and user tags
539
  response_text = re.sub(r'<\|system\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
540
  response_text = re.sub(r'<\|user\|>.*?<\|end\|>', '', response_text, flags=re.DOTALL)
541
  response_text = re.sub(r'<\|assistant\|>', '', response_text, flags=re.DOTALL)
542
 
543
+ # Adjusted regex pattern to extract document name and page number
544
+ document_match = re.search(r"(\d{6}_\d{12}_V\d+\.pdf),page:(\d+)", response_text)
545
+
546
  if document_match:
547
+ document_name = document_match.group(1) # Get the document name
548
+ page_number = document_match.group(2) # Get the page number
549
  else:
550
  document_name = "Unknown"
551
  page_number = "Unknown"
 
579
 
580
  return final_response
581
 
582
+
583
  # Define a new template specifically for GPT-4o-mini in VDB Details mode
584
  gpt4o_mini_template_details = f"""
585
  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.
 
1503
  # return prompt[0] if prompt else current_text
1504
 
1505
 
 
1506
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1507
 
1508
 
1509
 
 
1609
  # refresh_button = gr.Button("Refresh Images")
1610
  # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1611
 
1612
+
 
 
 
1613
 
1614
 
1615