Dave67350 commited on
Commit
64cc4b0
·
verified ·
1 Parent(s): 90e0d88

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +5 -14
Gradio_UI.py CHANGED
@@ -16,13 +16,15 @@ DOCUMENT_TO_MODULE = {
16
  "Data Governance Record": "tools.data_governance_record",
17
  "Human Oversight Strategy (Art. 14)": "tools.human_oversight_strategy",
18
  "Corrective Action Log": "tools.corrective_action_log"
 
 
19
  },
20
  "GDPR": {
21
  "Data Processing Record": "tools.gdpr_data_record"
22
  }
23
  }
24
 
25
- # === Fallback PDF Export (used only if tool doesn't have its own export method) ===
26
  def export_pdf(title, answers, lang="en"):
27
  pdf = FPDF()
28
  pdf.add_page()
@@ -85,18 +87,7 @@ def continue_conversation(user_input):
85
  messages.append({"role": "assistant", "content": f"🧠 {next_question}"})
86
  return messages, None
87
  else:
88
- tool = conversation_state["tool"]
89
- title = conversation_state["title"]
90
- lang = conversation_state["lang"]
91
- answers = conversation_state["answers"]
92
-
93
- # === Prefer tool's export function if available ===
94
- if hasattr(tool, "export_text_to_pdf"):
95
- content = "\n".join([f"- **{label}**: {answers.get(key, '')}" for key, label in conversation_state["questions"]])
96
- pdf_path = tool.export_text_to_pdf(content, language=lang)
97
- else:
98
- pdf_path = export_pdf(title, answers, lang=lang)
99
-
100
  messages.append({"role": "assistant", "content": "✅ Done! Your document is ready to download."})
101
  return messages, pdf_path
102
 
@@ -136,4 +127,4 @@ with gr.Blocks(title="Regulatory Compliance Generator") as demo:
136
  user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
137
  user_input.submit(lambda: "", None, user_input)
138
 
139
- demo.launch()
 
16
  "Data Governance Record": "tools.data_governance_record",
17
  "Human Oversight Strategy (Art. 14)": "tools.human_oversight_strategy",
18
  "Corrective Action Log": "tools.corrective_action_log"
19
+
20
+
21
  },
22
  "GDPR": {
23
  "Data Processing Record": "tools.gdpr_data_record"
24
  }
25
  }
26
 
27
+ # === PDF Export Function ===
28
  def export_pdf(title, answers, lang="en"):
29
  pdf = FPDF()
30
  pdf.add_page()
 
87
  messages.append({"role": "assistant", "content": f"🧠 {next_question}"})
88
  return messages, None
89
  else:
90
+ pdf_path = export_pdf(conversation_state["title"], conversation_state["answers"], lang=conversation_state["lang"])
 
 
 
 
 
 
 
 
 
 
 
91
  messages.append({"role": "assistant", "content": "✅ Done! Your document is ready to download."})
92
  return messages, pdf_path
93
 
 
127
  user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
128
  user_input.submit(lambda: "", None, user_input)
129
 
130
+ demo.launch()