mtyrrell commited on
Commit
41235aa
·
1 Parent(s): 5f9af61
Files changed (4) hide show
  1. app.py +15 -15
  2. app_interactions.jsonl +1 -4
  3. auditqa/utils.py +8 -17
  4. logs/app.log +37 -0
app.py CHANGED
@@ -49,23 +49,23 @@ load_dotenv()
49
  # token=SPACES_LOG )
50
 
51
  # Make logging optional
52
- SPACES_LOG = os.getenv("SPACES_LOG", "app_interactions.jsonl") # TESTING: local logging setup
53
  model_config = getconfig("model_params.cfg")
54
 
55
- # TESTING: local logging setup
56
- class LocalScheduler:
57
- def __init__(self, filepath):
58
- self.filepath = Path(filepath)
59
- self.lock = Lock()
60
 
61
- # Create the file if it doesn't exist
62
- if not self.filepath.exists():
63
- with self.filepath.open('w') as f:
64
- f.write('')
65
 
66
- # Instead of HuggingFace CommitScheduler, use local scheduler
67
- scheduler = LocalScheduler(SPACES_LOG) # TESTING: local logging setup
68
- JSON_DATASET_PATH = Path(SPACES_LOG) # TESTING: local logging setup
69
 
70
  # the logs are written to dataset repo periodically from local logs
71
  # https://huggingface.co/spaces/Wauplin/space_to_dataset_saver
@@ -549,13 +549,13 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
549
  """Handle 'okay' feedback submission"""
550
  ip = logs_data.get('client_ip', 'No IP found')
551
  location = logs_data.get('client_location', 'No location found')
552
- return submit_feedback("okay", logs_data) + (gr.update(visible=True, value=f"Debug - Client IP: {ip}, Location: {location}"),)
553
 
554
  def submit_feedback_not_okay(logs_data):
555
  """Handle 'not okay' feedback submission"""
556
  ip = logs_data.get('client_ip', 'No IP found')
557
  location = logs_data.get('client_location', 'No location found')
558
- return submit_feedback("not_okay", logs_data) + (gr.update(visible=True, value=f"Debug - Client IP: {ip}, Location: {location}"),)
559
 
560
  okay_btn.click(
561
  submit_feedback_okay,
 
49
  # token=SPACES_LOG )
50
 
51
  # Make logging optional
52
+ JSON_DATASET_PATH = "app_interactions.jsonl" # TESTING: local logging setup
53
  model_config = getconfig("model_params.cfg")
54
 
55
+ # # TESTING: local logging setup
56
+ # class LocalScheduler:
57
+ # def __init__(self, filepath):
58
+ # self.filepath = Path(filepath)
59
+ # self.lock = Lock()
60
 
61
+ # # Create the file if it doesn't exist
62
+ # if not self.filepath.exists():
63
+ # with self.filepath.open('w') as f:
64
+ # f.write('')
65
 
66
+ # # Instead of HuggingFace CommitScheduler, use local scheduler
67
+ # scheduler = LocalScheduler(JSON_DATASET_PATH) # TESTING: local logging setup
68
+ # JSON_DATASET_PATH = Path(JSON_DATASET_PATH) # TESTING: local logging setup
69
 
70
  # the logs are written to dataset repo periodically from local logs
71
  # https://huggingface.co/spaces/Wauplin/space_to_dataset_saver
 
549
  """Handle 'okay' feedback submission"""
550
  ip = logs_data.get('client_ip', 'No IP found')
551
  location = logs_data.get('client_location', 'No location found')
552
+ return submit_feedback("okay", logs_data) + (gr.update(visible=True, value=f"TESTING - Client IP: {ip}, Location: {location}"),)
553
 
554
  def submit_feedback_not_okay(logs_data):
555
  """Handle 'not okay' feedback submission"""
556
  ip = logs_data.get('client_ip', 'No IP found')
557
  location = logs_data.get('client_location', 'No location found')
558
+ return submit_feedback("not_okay", logs_data) + (gr.update(visible=True, value=f"TESTING - Client IP: {ip}, Location: {location}"),)
559
 
560
  okay_btn.click(
561
  submit_feedback_okay,
app_interactions.jsonl CHANGED
@@ -1,4 +1 @@
1
- {"session_id": "6b4e8dba-4839-4d6b-b1b4-2a45224a5a18", "client_ip": "127.0.0.1", "client_location": {"city": null, "region": null, "country": null, "latitude": null, "longitude": null}, "session_duration_seconds": 3e-06, "year": ["2023"], "question": "What are the key findings of this audit report?", "retriever": "BAAI/bge-large-en-v1.5", "endpoint_type": "DEDICATED", "reader": "meta-llama/Llama-3.1-8B-Instruct", "answer": "The audit reports provided cover the financial statements of Kifamba District Local Government and Buhweju District Local Government for the year ended 30th June 2023. The key findings from these reports are: 1. Management of Government Salary Payroll: * The Minister of Finance, Planning and Economic Development highlighted that expenditure on wage is a substantial percentage of all entity budgets, but significant results have not been achieved despite reforms <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. * A special audit on wage payroll in Local Government entities was carried out to establish the root causes of delays in salary payments and propose remedial measures. The audit covered four FYs from 2019/2020 to 2022/2023, and a separate detailed audit report was issued <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. 2. Implementation of Budget: * The Auditor General's report for Kifamba District Local Government found that the implementation of the approved budget was partially implemented, with some projects still ongoing <a href=\"#doc2\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>2</sup></span></a>. 3 Despite the Codeua ", "time": "1739433242.166489"}
2
- {"session_id": "6b4e8dba-4839-4d6b-b1b4-2a45224a5a18", "client_ip": "127.0.0.1", "client_location": {"city": null, "region": null, "country": null, "latitude": null, "longitude": null}, "session_duration_seconds": 3e-06, "year": ["2023"], "question": "What are the key findings of this audit report?", "retriever": "BAAI/bge-large-en-v1.5", "endpoint_type": "DEDICATED", "reader": "meta-llama/Llama-3.1-8B-Instruct", "answer": "The audit reports provided cover the financial statements of Kifamba District Local Government and Buhweju District Local Government for the year ended 30th June 2023. The key findings from these reports are: 1. Management of Government Salary Payroll: * The Minister of Finance, Planning and Economic Development highlighted that expenditure on wage is a substantial percentage of all entity budgets, but significant results have not been achieved despite reforms <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. * A special audit on wage payroll in Local Government entities was carried out to establish the root causes of delays in salary payments and propose remedial measures. The audit covered four FYs from 2019/2020 to 2022/2023, and a separate detailed audit report was issued <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. 2. Implementation of Budget: * The Auditor General's report for Kifamba District Local Government found that the implementation of the approved budget was partially implemented, with some projects still ongoing <a href=\"#doc2\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>2</sup></span></a>. 3 Despite the Codeua ", "time": "1739433242.166489", "feedback": "okay"}
3
- {"session_id": "cf8aac12-a43a-4098-8868-e5f5b113426f", "client_ip": "127.0.0.1", "client_location": {"city": null, "region": null, "country": null, "latitude": null, "longitude": null}, "session_duration_seconds": 3e-06, "year": ["2023"], "question": "What are the key findings of this audit report?", "retriever": "BAAI/bge-large-en-v1.5", "endpoint_type": "DEDICATED", "reader": "meta-llama/Llama-3.1-8B-Instruct", "answer": "The audit reports provided cover the financial statements of Kifamba District Local Government and Buhweju District Local Government for the year ended 30th June 2023. The key findings from these reports are: 1. Management of Government Salary Payroll: * The Minister of Finance, Planning and Economic Development highlighted that expenditure on wage is a substantial percentage of all entity budgets, but significant results have not been achieved despite reforms <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. * A special audit on wage payroll in Local Government entities was carried out to establish the root causes of delays in salary payments and propose remedial measures. The audit covered four FYs from 2019/2020 to 2022/2023, and a separate detailed audit report was issued <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. 2. Implementation of Budget: * The Auditor General's report for Kifamba District Local Government found that the implementation of the approved budget was partially implemented, with some projects still ongoing <a href=\"#doc2\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>2</sup></span></a>. 3 Despite the Codeua ", "time": "1739434342.056213"}
4
- {"session_id": "cf8aac12-a43a-4098-8868-e5f5b113426f", "client_ip": "127.0.0.1", "client_location": {"city": null, "region": null, "country": null, "latitude": null, "longitude": null}, "session_duration_seconds": 3e-06, "year": ["2023"], "question": "What are the key findings of this audit report?", "retriever": "BAAI/bge-large-en-v1.5", "endpoint_type": "DEDICATED", "reader": "meta-llama/Llama-3.1-8B-Instruct", "answer": "The audit reports provided cover the financial statements of Kifamba District Local Government and Buhweju District Local Government for the year ended 30th June 2023. The key findings from these reports are: 1. Management of Government Salary Payroll: * The Minister of Finance, Planning and Economic Development highlighted that expenditure on wage is a substantial percentage of all entity budgets, but significant results have not been achieved despite reforms <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. * A special audit on wage payroll in Local Government entities was carried out to establish the root causes of delays in salary payments and propose remedial measures. The audit covered four FYs from 2019/2020 to 2022/2023, and a separate detailed audit report was issued <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. 2. Implementation of Budget: * The Auditor General's report for Kifamba District Local Government found that the implementation of the approved budget was partially implemented, with some projects still ongoing <a href=\"#doc2\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>2</sup></span></a>. 3 Despite the Codeua ", "time": "1739434342.056213", "feedback": "okay"}
 
1
+ {"session_id": "fa279ca0-b89b-474e-817b-563ac9b88ac2", "client_ip": "127.0.0.1", "client_location": {"city": null, "region": null, "country": null, "latitude": null, "longitude": null}, "session_duration_seconds": 3e-06, "year": ["2023"], "question": "What are the key findings of this audit report?", "retriever": "BAAI/bge-large-en-v1.5", "endpoint_type": "DEDICATED", "reader": "meta-llama/Llama-3.1-8B-Instruct", "answer": "The audit reports provided cover the financial statements of Kifamba District Local Government and Buhweju District Local Government for the year ended 30th June 2023. The key findings from these reports are: 1. Management of Government Salary Payroll: * The Minister of Finance, Planning and Economic Development highlighted that expenditure on wage is a substantial percentage of all entity budgets, but significant results have not been achieved despite reforms <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. * A special audit on wage payroll in Local Government entities was carried out to establish the root causes of delays in salary payments and propose remedial measures. The audit covered four FYs from 2019/2020 to 2022/2023, and a separate detailed audit report was issued <a href=\"#doc1\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>1</sup></span></a>. 2. Implementation of Budget: * The Auditor General's report for Kifamba District Local Government found that the implementation of the approved budget was partially implemented, with some projects still ongoing <a href=\"#doc2\" class=\"a-doc-ref\" target=\"_self\"><span class='doc-ref'><sup>2</sup></span></a>. 3 Despite the Codeua ", "time": "1739438928.855079"}
 
 
 
auditqa/utils.py CHANGED
@@ -17,23 +17,14 @@ def save_logs(scheduler, JSON_DATASET_PATH, logs, feedback=None) -> None:
17
  this is to get the usage statistics of app and evaluate model performances.
18
  Also saves user feedback (when provided).
19
  """
20
- try:
21
- if feedback:
22
- logs["feedback"] = feedback #optional
23
-
24
- # Ensure the parent directory exists
25
- JSON_DATASET_PATH.parent.mkdir(parents=True, exist_ok=True)
26
-
27
- with scheduler.lock:
28
- with JSON_DATASET_PATH.open("a") as f:
29
- json.dump(logs, f)
30
- f.write("\n")
31
- logging.info("Logging completed successfully")
32
- except Exception as e:
33
- logging.error(f"Failed to save logs: {str(e)}")
34
- print(f"Error saving logs: {str(e)}")
35
-
36
-
37
 
38
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):
39
  if type == 'NVIDIA':
 
17
  this is to get the usage statistics of app and evaluate model performances.
18
  Also saves user feedback (when provided).
19
  """
20
+ if feedback:
21
+ logs["feedback"] = feedback #optional
22
+
23
+ with scheduler.lock:
24
+ with open(JSON_DATASET_PATH, 'a') as f:
25
+ json.dump(logs, f)
26
+ f.write("\n")
27
+ print("logging done")
 
 
 
 
 
 
 
 
 
28
 
29
  def get_message_template(type, SYSTEM_PROMPT, USER_PROMPT):
30
  if type == 'NVIDIA':
logs/app.log CHANGED
@@ -1221,3 +1221,40 @@ Make sure your token has the correct permissions.
1221
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Serverless endpoint activated
1222
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Initializing InferenceClient with model: meta-llama/Meta-Llama-3-8B-Instruct
1223
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Serverless InferenceClient initialization successful
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1221
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Serverless endpoint activated
1222
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Initializing InferenceClient with model: meta-llama/Meta-Llama-3-8B-Instruct
1223
  2025-02-13 08:12:22,056 - auditqa.reader - INFO - Serverless InferenceClient initialization successful
1224
+ 2025-02-13 09:21:30,180 - datasets - INFO - PyTorch version 2.4.0 available.
1225
+ 2025-02-13 09:21:30,295 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: BAAI/bge-large-en-v1.5
1226
+ 2025-02-13 09:21:32,193 - httpx - INFO - HTTP Request: GET https://checkip.amazonaws.com/ "HTTP/1.1 200 "
1227
+ 2025-02-13 09:21:32,198 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/startup-events "HTTP/1.1 200 OK"
1228
+ 2025-02-13 09:21:32,211 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
1229
+ 2025-02-13 09:21:32,760 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
1230
+ 2025-02-13 09:23:52,792 - __main__ - DEBUG - Chat function called with query: What are the key findings of this audit report?
1231
+ 2025-02-13 09:23:52,793 - __main__ - DEBUG - Client IP: 127.0.0.1
1232
+ 2025-02-13 09:23:52,794 - __main__ - DEBUG - Session ID: None
1233
+ 2025-02-13 09:23:53,108 - __main__ - DEBUG - Created new session: c2e134ad-28d4-4e6b-8fd0-5de3d826ac16
1234
+ 2025-02-13 09:23:53,110 - __main__ - DEBUG - Session duration: 3e-06
1235
+ 2025-02-13 09:23:53,111 - auditqa.retriever - INFO - Retriever activated
1236
+ 2025-02-13 09:23:54,568 - sentence_transformers.cross_encoder.CrossEncoder - INFO - Use pytorch device: mps
1237
+ 2025-02-13 09:23:57,180 - httpx - INFO - HTTP Request: POST https://ff3f0448-0a00-470e-9956-49efa3071db3.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/allreports/points/search "HTTP/1.1 200 OK"
1238
+ 2025-02-13 09:24:04,903 - auditqa.retriever - INFO - retrieved paragraphs:3
1239
+ 2025-02-13 09:24:05,120 - auditqa.reader - INFO - Serverless endpoint activated
1240
+ 2025-02-13 09:24:05,120 - auditqa.reader - INFO - Initializing InferenceClient with model: meta-llama/Meta-Llama-3-8B-Instruct
1241
+ 2025-02-13 09:24:05,120 - auditqa.reader - INFO - Serverless InferenceClient initialization successful
1242
+ 2025-02-13 09:28:28,531 - __main__ - INFO - App launched
1243
+ 2025-02-13 09:28:35,576 - datasets - INFO - PyTorch version 2.4.0 available.
1244
+ 2025-02-13 09:28:35,688 - sentence_transformers.SentenceTransformer - INFO - Load pretrained SentenceTransformer: BAAI/bge-large-en-v1.5
1245
+ 2025-02-13 09:28:37,625 - httpx - INFO - HTTP Request: GET https://checkip.amazonaws.com/ "HTTP/1.1 200 "
1246
+ 2025-02-13 09:28:37,646 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7861/startup-events "HTTP/1.1 200 OK"
1247
+ 2025-02-13 09:28:37,658 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7861/ "HTTP/1.1 200 OK"
1248
+ 2025-02-13 09:28:38,210 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
1249
+ 2025-02-13 09:28:42,069 - __main__ - DEBUG - Chat function called with query: What are the key findings of this audit report?
1250
+ 2025-02-13 09:28:42,070 - __main__ - DEBUG - Client IP: 127.0.0.1
1251
+ 2025-02-13 09:28:42,070 - __main__ - DEBUG - Session ID: None
1252
+ 2025-02-13 09:28:42,392 - __main__ - DEBUG - Created new session: fa279ca0-b89b-474e-817b-563ac9b88ac2
1253
+ 2025-02-13 09:28:42,393 - __main__ - DEBUG - Session duration: 3e-06
1254
+ 2025-02-13 09:28:42,394 - auditqa.retriever - INFO - Retriever activated
1255
+ 2025-02-13 09:28:43,661 - sentence_transformers.cross_encoder.CrossEncoder - INFO - Use pytorch device: mps
1256
+ 2025-02-13 09:28:46,213 - httpx - INFO - HTTP Request: POST https://ff3f0448-0a00-470e-9956-49efa3071db3.europe-west3-0.gcp.cloud.qdrant.io:6333/collections/allreports/points/search "HTTP/1.1 200 OK"
1257
+ 2025-02-13 09:28:48,688 - auditqa.retriever - INFO - retrieved paragraphs:3
1258
+ 2025-02-13 09:28:48,855 - auditqa.reader - INFO - Serverless endpoint activated
1259
+ 2025-02-13 09:28:48,855 - auditqa.reader - INFO - Initializing InferenceClient with model: meta-llama/Meta-Llama-3-8B-Instruct
1260
+ 2025-02-13 09:28:48,855 - auditqa.reader - INFO - Serverless InferenceClient initialization successful