Spaces:
Sleeping
Sleeping
Update tools/data_governance_record.py
Browse files- tools/data_governance_record.py +24 -14
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, 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"
|
|
@@ -16,23 +16,25 @@ def export_text_to_pdf(text, metadata, output_path=None, language="en"):
|
|
| 16 |
pdf.add_page()
|
| 17 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 18 |
|
|
|
|
| 19 |
pdf.set_font("Arial", 'B', 16)
|
| 20 |
pdf.set_text_color(0, 51, 102)
|
| 21 |
title = "Data Governance and Quality Record" if language == "en" else "Dossier de Gouvernance et Qualité des Données"
|
| 22 |
pdf.cell(0, 15, title, ln=True, align='C')
|
| 23 |
pdf.ln(10)
|
| 24 |
|
| 25 |
-
# Metadata
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
|
|
|
| 33 |
pdf.set_font("Arial", '', 12)
|
| 34 |
pdf.set_text_color(0, 0, 0)
|
| 35 |
-
|
| 36 |
for line in text.strip().split('\n'):
|
| 37 |
line = line.strip()
|
| 38 |
if line.startswith("## "):
|
|
@@ -62,6 +64,7 @@ def export_text_to_pdf(text, metadata, output_path=None, language="en"):
|
|
| 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."),
|
|
@@ -79,7 +82,7 @@ QUESTIONS = [
|
|
| 79 |
def get_questions():
|
| 80 |
return QUESTIONS
|
| 81 |
|
| 82 |
-
# ===
|
| 83 |
def run_tool():
|
| 84 |
state = {"step": 0, "answers": {}}
|
| 85 |
|
|
@@ -96,11 +99,14 @@ def run_tool():
|
|
| 96 |
state["step"] += 1
|
| 97 |
return next_q, state, None
|
| 98 |
|
| 99 |
-
|
|
|
|
| 100 |
detected_lang = detect(content)
|
|
|
|
| 101 |
metadata = {
|
| 102 |
-
"
|
| 103 |
-
"
|
|
|
|
| 104 |
"timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 105 |
}
|
| 106 |
|
|
@@ -108,7 +114,11 @@ def run_tool():
|
|
| 108 |
return "✅ Documentation complete. Download below.", {"done": True}, pdf_path
|
| 109 |
|
| 110 |
with gr.Blocks(title="Data Governance Tool") as demo:
|
| 111 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
msg = gr.Textbox(label="Your answer")
|
| 113 |
state_var = gr.State(state)
|
| 114 |
file_output = gr.File(label="Download PDF")
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
# === PDF Export Function ===
|
| 10 |
+
def export_text_to_pdf(text, metadata=None, 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"
|
|
|
|
| 16 |
pdf.add_page()
|
| 17 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 18 |
|
| 19 |
+
# Title
|
| 20 |
pdf.set_font("Arial", 'B', 16)
|
| 21 |
pdf.set_text_color(0, 51, 102)
|
| 22 |
title = "Data Governance and Quality Record" if language == "en" else "Dossier de Gouvernance et Qualité des Données"
|
| 23 |
pdf.cell(0, 15, title, ln=True, align='C')
|
| 24 |
pdf.ln(10)
|
| 25 |
|
| 26 |
+
# Metadata
|
| 27 |
+
if metadata:
|
| 28 |
+
pdf.set_font("Arial", '', 12)
|
| 29 |
+
pdf.set_text_color(90, 90, 90)
|
| 30 |
+
pdf.multi_cell(0, 10, f"Organization: {metadata.get('organization', 'N/A')}")
|
| 31 |
+
pdf.multi_cell(0, 10, f"Completed by: {metadata.get('completed_by', 'N/A')} ({metadata.get('role', 'N/A')})")
|
| 32 |
+
pdf.multi_cell(0, 10, f"Timestamp: {metadata.get('timestamp', 'N/A')}")
|
| 33 |
+
pdf.ln(5)
|
| 34 |
|
| 35 |
+
# Body
|
| 36 |
pdf.set_font("Arial", '', 12)
|
| 37 |
pdf.set_text_color(0, 0, 0)
|
|
|
|
| 38 |
for line in text.strip().split('\n'):
|
| 39 |
line = line.strip()
|
| 40 |
if line.startswith("## "):
|
|
|
|
| 64 |
|
| 65 |
# === Questions ===
|
| 66 |
QUESTIONS = [
|
| 67 |
+
("organization", "What is the name of your organization?"),
|
| 68 |
("completed_by", "What is your full name?"),
|
| 69 |
("role", "What is your role in the organization?"),
|
| 70 |
("dataset_description", "Please describe the dataset(s) used."),
|
|
|
|
| 82 |
def get_questions():
|
| 83 |
return QUESTIONS
|
| 84 |
|
| 85 |
+
# === Run Tool ===
|
| 86 |
def run_tool():
|
| 87 |
state = {"step": 0, "answers": {}}
|
| 88 |
|
|
|
|
| 99 |
state["step"] += 1
|
| 100 |
return next_q, state, None
|
| 101 |
|
| 102 |
+
# Build content and metadata
|
| 103 |
+
content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in QUESTIONS])
|
| 104 |
detected_lang = detect(content)
|
| 105 |
+
|
| 106 |
metadata = {
|
| 107 |
+
"organization": answers.get("organization", "N/A"),
|
| 108 |
+
"completed_by": answers.get("completed_by", "N/A"),
|
| 109 |
+
"role": answers.get("role", "N/A"),
|
| 110 |
"timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 111 |
}
|
| 112 |
|
|
|
|
| 114 |
return "✅ Documentation complete. Download below.", {"done": True}, pdf_path
|
| 115 |
|
| 116 |
with gr.Blocks(title="Data Governance Tool") as demo:
|
| 117 |
+
chatbot = gr.Chatbot(
|
| 118 |
+
label="📊 Data Governance Assistant",
|
| 119 |
+
value=[{"role": "assistant", "content": QUESTIONS[0][1]}],
|
| 120 |
+
type="messages"
|
| 121 |
+
)
|
| 122 |
msg = gr.Textbox(label="Your answer")
|
| 123 |
state_var = gr.State(state)
|
| 124 |
file_output = gr.File(label="Download PDF")
|