Dave67350 commited on
Commit
e28c25d
·
verified ·
1 Parent(s): 653c010

Update tools/post_market_monitoring.py

Browse files
Files changed (1) hide show
  1. tools/post_market_monitoring.py +31 -5
tools/post_market_monitoring.py CHANGED
@@ -1,12 +1,15 @@
1
- # tools/post_market_monitoring.py
 
2
  import datetime
3
  import re
4
  from fpdf import FPDF
5
  from langdetect import detect
6
  import gradio as gr
7
 
 
 
8
  # === PDF Export ===
9
- def export_text_to_pdf(text, output_path=None, language="en"):
10
  if output_path is None:
11
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
12
  output_path = f"post_market_monitoring_{timestamp}.pdf"
@@ -21,6 +24,15 @@ def export_text_to_pdf(text, output_path=None, language="en"):
21
  pdf.cell(0, 15, title, ln=True, align='C')
22
  pdf.ln(10)
23
 
 
 
 
 
 
 
 
 
 
24
  pdf.set_font("Arial", '', 12)
25
  pdf.set_text_color(0, 0, 0)
26
  for line in text.strip().split('\n'):
@@ -49,8 +61,8 @@ def export_text_to_pdf(text, output_path=None, language="en"):
49
  pdf.output(output_path)
50
  return output_path
51
 
52
- # === Questions ===
53
- QUESTIONS = [
54
  ("system_name", "What is the name of the AI system being monitored?"),
55
  ("monitoring_objectives", "What are the main objectives of post-market monitoring?"),
56
  ("monitoring_process", "Describe the process for collecting post-market data."),
@@ -63,6 +75,8 @@ QUESTIONS = [
63
  ("update_strategy", "How will monitoring findings be used to update the system?")
64
  ]
65
 
 
 
66
  def get_questions():
67
  return QUESTIONS
68
 
@@ -86,8 +100,10 @@ def run_tool():
86
  # Final format
87
  content = f"""
88
  # Post-Market Monitoring Plan
 
89
  ## System Overview
90
  - **System Name**: {answers.get('system_name', '')}
 
91
  ## Monitoring Strategy
92
  - **Objectives**: {answers.get('monitoring_objectives', '')}
93
  - **Process**: {answers.get('monitoring_process', '')}
@@ -95,15 +111,25 @@ def run_tool():
95
  - **Data Sources**: {answers.get('data_sources', '')}
96
  - **Trigger Events**: {answers.get('trigger_events', '')}
97
  - **Frequency**: {answers.get('frequency', '')}
 
98
  ## Response & Documentation
99
  - **Corrective Actions**: {answers.get('corrective_actions', '')}
100
  - **Documentation Approach**: {answers.get('documentation', '')}
101
  - **Update Strategy**: {answers.get('update_strategy', '')}
 
102
  ---
103
  Generated by AI Act Assistant.
104
  """
 
105
  lang = detect(content)
106
- pdf_path = export_text_to_pdf(content, language=lang)
 
 
 
 
 
 
 
107
  return "✅ Plan completed. Download your PDF below.", {"done": True}, pdf_path
108
 
109
  with gr.Blocks(title="Post-Market Monitoring Tool") as demo:
 
1
+ #!/usr/bin/env python
2
+ # coding=utf-8
3
  import datetime
4
  import re
5
  from fpdf import FPDF
6
  from langdetect import detect
7
  import gradio as gr
8
 
9
+ from tools.common import prepend_metadata_questions # ✅ Shared metadata logic
10
+
11
  # === PDF Export ===
12
+ def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
13
  if output_path is None:
14
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
15
  output_path = f"post_market_monitoring_{timestamp}.pdf"
 
24
  pdf.cell(0, 15, title, ln=True, align='C')
25
  pdf.ln(10)
26
 
27
+ # Metadata block
28
+ if metadata:
29
+ pdf.set_font("Arial", '', 12)
30
+ pdf.set_text_color(90, 90, 90)
31
+ pdf.multi_cell(0, 10, f"Organization: {metadata.get('organization', 'N/A')}")
32
+ pdf.multi_cell(0, 10, f"Completed by: {metadata.get('completed_by', 'N/A')} ({metadata.get('role', 'N/A')})")
33
+ pdf.multi_cell(0, 10, f"Timestamp: {metadata.get('timestamp', 'N/A')}")
34
+ pdf.ln(5)
35
+
36
  pdf.set_font("Arial", '', 12)
37
  pdf.set_text_color(0, 0, 0)
38
  for line in text.strip().split('\n'):
 
61
  pdf.output(output_path)
62
  return output_path
63
 
64
+ # === Base Questions ===
65
+ BASE_QUESTIONS = [
66
  ("system_name", "What is the name of the AI system being monitored?"),
67
  ("monitoring_objectives", "What are the main objectives of post-market monitoring?"),
68
  ("monitoring_process", "Describe the process for collecting post-market data."),
 
75
  ("update_strategy", "How will monitoring findings be used to update the system?")
76
  ]
77
 
78
+ QUESTIONS = prepend_metadata_questions(BASE_QUESTIONS)
79
+
80
  def get_questions():
81
  return QUESTIONS
82
 
 
100
  # Final format
101
  content = f"""
102
  # Post-Market Monitoring Plan
103
+
104
  ## System Overview
105
  - **System Name**: {answers.get('system_name', '')}
106
+
107
  ## Monitoring Strategy
108
  - **Objectives**: {answers.get('monitoring_objectives', '')}
109
  - **Process**: {answers.get('monitoring_process', '')}
 
111
  - **Data Sources**: {answers.get('data_sources', '')}
112
  - **Trigger Events**: {answers.get('trigger_events', '')}
113
  - **Frequency**: {answers.get('frequency', '')}
114
+
115
  ## Response & Documentation
116
  - **Corrective Actions**: {answers.get('corrective_actions', '')}
117
  - **Documentation Approach**: {answers.get('documentation', '')}
118
  - **Update Strategy**: {answers.get('update_strategy', '')}
119
+
120
  ---
121
  Generated by AI Act Assistant.
122
  """
123
+
124
  lang = detect(content)
125
+ metadata = {
126
+ "organization": answers.get("organization_name", "N/A"),
127
+ "completed_by": answers.get("user_name", "N/A"),
128
+ "role": answers.get("user_role", "N/A"),
129
+ "timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
130
+ }
131
+
132
+ pdf_path = export_text_to_pdf(content, metadata=metadata, language=lang)
133
  return "✅ Plan completed. Download your PDF below.", {"done": True}, pdf_path
134
 
135
  with gr.Blocks(title="Post-Market Monitoring Tool") as demo: