Spaces:
Sleeping
Sleeping
Update tools/data_governance_record.py
Browse files
tools/data_governance_record.py
CHANGED
|
@@ -7,7 +7,7 @@ from langdetect import detect
|
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
# === PDF Export Function ===
|
| 10 |
-
def export_text_to_pdf(text, output_path=None, language="en"):
|
| 11 |
if output_path is None:
|
| 12 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 13 |
output_path = f"data_governance_record_{timestamp}.pdf"
|
|
@@ -22,6 +22,14 @@ def export_text_to_pdf(text, output_path=None, language="en"):
|
|
| 22 |
pdf.cell(0, 15, title, ln=True, align='C')
|
| 23 |
pdf.ln(10)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
pdf.set_font("Arial", '', 12)
|
| 26 |
pdf.set_text_color(0, 0, 0)
|
| 27 |
|
|
@@ -54,6 +62,8 @@ def export_text_to_pdf(text, output_path=None, language="en"):
|
|
| 54 |
|
| 55 |
# === Questions ===
|
| 56 |
QUESTIONS = [
|
|
|
|
|
|
|
| 57 |
("dataset_description", "Please describe the dataset(s) used."),
|
| 58 |
("data_sources", "What are the sources of the data?"),
|
| 59 |
("data_collection_method", "How was the data collected?"),
|
|
@@ -86,9 +96,15 @@ def run_tool():
|
|
| 86 |
state["step"] += 1
|
| 87 |
return next_q, state, None
|
| 88 |
|
| 89 |
-
content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in QUESTIONS])
|
| 90 |
detected_lang = detect(content)
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return "✅ Documentation complete. Download below.", {"done": True}, pdf_path
|
| 93 |
|
| 94 |
with gr.Blocks(title="Data Governance Tool") as demo:
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
# === PDF Export Function ===
|
| 10 |
+
def export_text_to_pdf(text, metadata, output_path=None, language="en"):
|
| 11 |
if output_path is None:
|
| 12 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 13 |
output_path = f"data_governance_record_{timestamp}.pdf"
|
|
|
|
| 22 |
pdf.cell(0, 15, title, ln=True, align='C')
|
| 23 |
pdf.ln(10)
|
| 24 |
|
| 25 |
+
# Metadata below the title
|
| 26 |
+
pdf.set_font("Arial", '', 12)
|
| 27 |
+
pdf.set_text_color(90, 90, 90)
|
| 28 |
+
pdf.multi_cell(0, 10, f"Completed by: {metadata.get('completed_by', 'N/A')}")
|
| 29 |
+
pdf.multi_cell(0, 10, f"Role: {metadata.get('role', 'N/A')}")
|
| 30 |
+
pdf.multi_cell(0, 10, f"Date: {metadata.get('timestamp', 'N/A')}")
|
| 31 |
+
pdf.ln(5)
|
| 32 |
+
|
| 33 |
pdf.set_font("Arial", '', 12)
|
| 34 |
pdf.set_text_color(0, 0, 0)
|
| 35 |
|
|
|
|
| 62 |
|
| 63 |
# === Questions ===
|
| 64 |
QUESTIONS = [
|
| 65 |
+
("completed_by", "What is your full name?"),
|
| 66 |
+
("role", "What is your role in the organization?"),
|
| 67 |
("dataset_description", "Please describe the dataset(s) used."),
|
| 68 |
("data_sources", "What are the sources of the data?"),
|
| 69 |
("data_collection_method", "How was the data collected?"),
|
|
|
|
| 96 |
state["step"] += 1
|
| 97 |
return next_q, state, None
|
| 98 |
|
| 99 |
+
content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in QUESTIONS[2:]])
|
| 100 |
detected_lang = detect(content)
|
| 101 |
+
metadata = {
|
| 102 |
+
"completed_by": answers.get("completed_by", ""),
|
| 103 |
+
"role": answers.get("role", ""),
|
| 104 |
+
"timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
pdf_path = export_text_to_pdf(content, metadata=metadata, language=detected_lang)
|
| 108 |
return "✅ Documentation complete. Download below.", {"done": True}, pdf_path
|
| 109 |
|
| 110 |
with gr.Blocks(title="Data Governance Tool") as demo:
|