Dave67350 commited on
Commit
55ebae5
·
verified ·
1 Parent(s): 3f6b244

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +12 -7
Gradio_UI.py CHANGED
@@ -12,6 +12,8 @@ from smolagents.memory import MemoryStep
12
  from smolagents.utils import _is_package_available
13
 
14
  import gradio as gr
 
 
15
  from fpdf import FPDF
16
  from langdetect import detect
17
 
@@ -51,8 +53,6 @@ QUESTIONS = [
51
  ("compliance_contact", "Who is the contact person for compliance (email or name)?")
52
  ]
53
 
54
- RESPONSES = {}
55
-
56
  # === Interactive Collection Flow ===
57
  def step_by_step_agent(user_input, state):
58
  if state is None:
@@ -98,15 +98,13 @@ def step_by_step_agent(user_input, state):
98
  Generated by AI Act Assistant.
99
  """
100
 
101
- import csv
102
- import datetime
103
-
104
  try:
105
  detected_lang = detect(filled_template)
106
  except:
107
  detected_lang = "en"
108
 
109
  flag = "🇬🇧" if detected_lang == "en" else "🇫🇷"
 
110
  # Save to CSV
111
  csv_file = "ai_act_registers.csv"
112
  fieldnames = [key for key, _ in QUESTIONS] + ["timestamp"]
@@ -120,13 +118,14 @@ import datetime
120
  writer.writerow(row_data)
121
 
122
  pdf_path = export_text_to_pdf(filled_template, language=detected_lang)
123
- return f"{flag} Language detected: {detected_lang.upper()}
124
- ✅ All answers received. Download your AI Act compliance PDF below.", {"done": True, "pdf": pdf_path}
125
 
126
  # === UI for Step-by-Step Form ===
127
  def launch_step_by_step_ui():
128
  with gr.Blocks(fill_height=True) as demo:
 
129
  csv_download = gr.File(value="ai_act_registers.csv", label="📥 Download All Registers (.csv)", visible=os.path.exists("ai_act_registers.csv"))
 
130
  initial_message = gr.ChatMessage(role="assistant", content=(
131
  "👋 Welcome! I will guide you through the AI Act compliance form.\n"
132
  "Let's begin with a few questions to generate your compliance register.\n"
@@ -151,8 +150,14 @@ def launch_step_by_step_ui():
151
  def restart_conversation():
152
  return [initial_message], {"step": 0, "answers": {}}, None
153
 
 
 
 
 
 
154
  msg.submit(chat_logic, [msg, state], [chatbot, state, file_output])
155
  restart_button.click(restart_conversation, outputs=[chatbot, state, file_output])
 
156
 
157
  demo.launch()
158
 
 
12
  from smolagents.utils import _is_package_available
13
 
14
  import gradio as gr
15
+ import csv
16
+ import datetime
17
  from fpdf import FPDF
18
  from langdetect import detect
19
 
 
53
  ("compliance_contact", "Who is the contact person for compliance (email or name)?")
54
  ]
55
 
 
 
56
  # === Interactive Collection Flow ===
57
  def step_by_step_agent(user_input, state):
58
  if state is None:
 
98
  Generated by AI Act Assistant.
99
  """
100
 
 
 
 
101
  try:
102
  detected_lang = detect(filled_template)
103
  except:
104
  detected_lang = "en"
105
 
106
  flag = "🇬🇧" if detected_lang == "en" else "🇫🇷"
107
+
108
  # Save to CSV
109
  csv_file = "ai_act_registers.csv"
110
  fieldnames = [key for key, _ in QUESTIONS] + ["timestamp"]
 
118
  writer.writerow(row_data)
119
 
120
  pdf_path = export_text_to_pdf(filled_template, language=detected_lang)
121
+ return f"{flag} Language detected: {detected_lang.upper()}\n✅ All answers received. Download your AI Act compliance PDF below.", {"done": True, "pdf": pdf_path}
 
122
 
123
  # === UI for Step-by-Step Form ===
124
  def launch_step_by_step_ui():
125
  with gr.Blocks(fill_height=True) as demo:
126
+ reset_csv = gr.Button("🗑️ Reset CSV File")
127
  csv_download = gr.File(value="ai_act_registers.csv", label="📥 Download All Registers (.csv)", visible=os.path.exists("ai_act_registers.csv"))
128
+
129
  initial_message = gr.ChatMessage(role="assistant", content=(
130
  "👋 Welcome! I will guide you through the AI Act compliance form.\n"
131
  "Let's begin with a few questions to generate your compliance register.\n"
 
150
  def restart_conversation():
151
  return [initial_message], {"step": 0, "answers": {}}, None
152
 
153
+ def delete_csv():
154
+ if os.path.exists("ai_act_registers.csv"):
155
+ os.remove("ai_act_registers.csv")
156
+ return None
157
+
158
  msg.submit(chat_logic, [msg, state], [chatbot, state, file_output])
159
  restart_button.click(restart_conversation, outputs=[chatbot, state, file_output])
160
+ reset_csv.click(delete_csv, outputs=[])
161
 
162
  demo.launch()
163