Dave67350 commited on
Commit
720e4b6
·
verified ·
1 Parent(s): b831aaa

Update tools/gdpr_data_record.py

Browse files
Files changed (1) hide show
  1. tools/gdpr_data_record.py +11 -11
tools/gdpr_data_record.py CHANGED
@@ -4,6 +4,7 @@ import re
4
  from fpdf import FPDF
5
  from langdetect import detect
6
  import gradio as gr
 
7
 
8
  # === PDF Export Function ===
9
  def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
@@ -22,7 +23,7 @@ def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
22
  pdf.cell(0, 15, title, ln=True, align='C')
23
  pdf.ln(10)
24
 
25
- # Metadata
26
  if metadata:
27
  pdf.set_font("Arial", '', 12)
28
  pdf.set_text_color(90, 90, 90)
@@ -31,7 +32,7 @@ def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
31
  pdf.multi_cell(0, 10, f"Timestamp: {metadata.get('timestamp', 'N/A')}")
32
  pdf.ln(5)
33
 
34
- # Content
35
  pdf.set_font("Arial", '', 12)
36
  pdf.set_text_color(0, 0, 0)
37
  for line in text.strip().split('\n'):
@@ -58,11 +59,8 @@ def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
58
  pdf.output(output_path)
59
  return output_path
60
 
61
- # === Questions (with metadata) ===
62
- QUESTIONS = [
63
- ("organization", "What is the name of your organization?"),
64
- ("completed_by", "What is your full name?"),
65
- ("role", "What is your role in the organization?"),
66
  ("purpose", "What is the purpose of the data processing activity?"),
67
  ("data_categories", "What categories of personal data are processed?"),
68
  ("data_subjects", "What types of data subjects are affected?"),
@@ -73,6 +71,9 @@ QUESTIONS = [
73
  ("dpo", "Who is the Data Protection Officer (if any)?"),
74
  ]
75
 
 
 
 
76
  def get_questions():
77
  return QUESTIONS
78
 
@@ -92,7 +93,6 @@ def run_tool():
92
  state["step"] += 1
93
  return next_q, state, None
94
 
95
- # Compile content and metadata
96
  content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in QUESTIONS])
97
  detected_lang = detect(content)
98
 
@@ -104,14 +104,14 @@ def run_tool():
104
  }
105
 
106
  pdf_path = export_text_to_pdf(content, metadata=metadata, language=detected_lang)
107
- return "✅ Record completed. Download your GDPR data processing record below.", {"done": True}, pdf_path
108
 
109
- # === Gradio UI ===
110
  with gr.Blocks(title="GDPR Data Processing Record Tool") as demo:
111
  chatbot = gr.Chatbot(label="🔐 GDPR Assistant", value=[{"role": "assistant", "content": QUESTIONS[0][1]}], type="messages")
112
  msg = gr.Textbox(label="Your answer")
113
  state_var = gr.State(state)
114
- file_output = gr.File(label="Download PDF", visible=True)
115
  reset_btn = gr.Button("🔁 Restart")
116
 
117
  def chat_logic(msg_in, state_in):
 
4
  from fpdf import FPDF
5
  from langdetect import detect
6
  import gradio as gr
7
+ from tools.common import prepend_metadata_questions # 👈 import metadata logic
8
 
9
  # === PDF Export Function ===
10
  def export_text_to_pdf(text, metadata=None, output_path=None, language="en"):
 
23
  pdf.cell(0, 15, title, ln=True, align='C')
24
  pdf.ln(10)
25
 
26
+ # Metadata section
27
  if metadata:
28
  pdf.set_font("Arial", '', 12)
29
  pdf.set_text_color(90, 90, 90)
 
32
  pdf.multi_cell(0, 10, f"Timestamp: {metadata.get('timestamp', 'N/A')}")
33
  pdf.ln(5)
34
 
35
+ # Main content
36
  pdf.set_font("Arial", '', 12)
37
  pdf.set_text_color(0, 0, 0)
38
  for line in text.strip().split('\n'):
 
59
  pdf.output(output_path)
60
  return output_path
61
 
62
+ # === GDPR-Specific Questions (excluding metadata) ===
63
+ BASE_QUESTIONS = [
 
 
 
64
  ("purpose", "What is the purpose of the data processing activity?"),
65
  ("data_categories", "What categories of personal data are processed?"),
66
  ("data_subjects", "What types of data subjects are affected?"),
 
71
  ("dpo", "Who is the Data Protection Officer (if any)?"),
72
  ]
73
 
74
+ # Inject metadata
75
+ QUESTIONS = prepend_metadata_questions(BASE_QUESTIONS)
76
+
77
  def get_questions():
78
  return QUESTIONS
79
 
 
93
  state["step"] += 1
94
  return next_q, state, None
95
 
 
96
  content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in QUESTIONS])
97
  detected_lang = detect(content)
98
 
 
104
  }
105
 
106
  pdf_path = export_text_to_pdf(content, metadata=metadata, language=detected_lang)
107
+ return "✅ Record complete. Download your GDPR processing record below.", {"done": True}, pdf_path
108
 
109
+ # Gradio UI
110
  with gr.Blocks(title="GDPR Data Processing Record Tool") as demo:
111
  chatbot = gr.Chatbot(label="🔐 GDPR Assistant", value=[{"role": "assistant", "content": QUESTIONS[0][1]}], type="messages")
112
  msg = gr.Textbox(label="Your answer")
113
  state_var = gr.State(state)
114
+ file_output = gr.File(label="Download PDF")
115
  reset_btn = gr.Button("🔁 Restart")
116
 
117
  def chat_logic(msg_in, state_in):