Spaces:
Sleeping
Sleeping
Update tools/ai_act_generator.py
Browse files- tools/ai_act_generator.py +31 -20
tools/ai_act_generator.py
CHANGED
|
@@ -165,29 +165,40 @@ Generated by AI Act Assistant.
|
|
| 165 |
✅ All answers received. Your PDF is ready below:
|
| 166 |
👉 Click the download button to save your AI Act compliance register.""", {"done": True, "pdf": pdf_path}, pdf_path
|
| 167 |
|
| 168 |
-
# === UI for Step-by-Step Form ===
|
| 169 |
def launch_step_by_step_ui():
|
| 170 |
-
with gr.Blocks(
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
.absolute.bottom-4.right-4,
|
| 175 |
-
a[href*="gradio.app"],
|
| 176 |
-
a[href*="huggingface.co"],
|
| 177 |
-
.svelte-drgfjz[data-testid="clear-button"],
|
| 178 |
-
.svelte-1ipelgc[data-testid="block-settings-button"] {
|
| 179 |
-
display: none !important;
|
| 180 |
-
}
|
| 181 |
-
</style>
|
| 182 |
-
""")
|
| 183 |
-
|
| 184 |
initial_question = QUESTIONS[0][1]
|
| 185 |
-
initial_message = gr.ChatMessage(role="assistant", content=""
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
What is the name of your organization?
|
| 190 |
-
""")
|
| 191 |
...
|
| 192 |
|
| 193 |
stored_messages = [initial_message]
|
|
|
|
| 165 |
✅ All answers received. Your PDF is ready below:
|
| 166 |
👉 Click the download button to save your AI Act compliance register.""", {"done": True, "pdf": pdf_path}, pdf_path
|
| 167 |
|
|
|
|
| 168 |
def launch_step_by_step_ui():
|
| 169 |
+
with gr.Blocks(
|
| 170 |
+
fill_height=True,
|
| 171 |
+
css=".prose > div.flex.justify-between.items-center { display: none !important; }"
|
| 172 |
+
) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
initial_question = QUESTIONS[0][1]
|
| 174 |
+
initial_message = gr.ChatMessage(role="assistant", content=f"👋 Welcome!\n\n{initial_question}")
|
| 175 |
+
stored_messages = [initial_message]
|
| 176 |
+
|
| 177 |
+
chatbot = gr.Chatbot(type="messages", value=stored_messages)
|
| 178 |
+
msg = gr.Textbox(label="Your answer")
|
| 179 |
+
state = gr.State()
|
| 180 |
+
file_output = gr.File(label="Download PDF", visible=True)
|
| 181 |
+
restart_button = gr.Button("🔁 Restart")
|
| 182 |
+
|
| 183 |
+
def chat_logic(user_msg, state):
|
| 184 |
+
reply, updated_state, file_path = step_by_step_agent(user_msg, state)
|
| 185 |
+
messages = [gr.ChatMessage(role="user", content=user_msg)]
|
| 186 |
+
|
| 187 |
+
if isinstance(reply, str):
|
| 188 |
+
messages.append(gr.ChatMessage(role="assistant", content=reply))
|
| 189 |
+
|
| 190 |
+
if not file_path or not os.path.isfile(file_path):
|
| 191 |
+
file_path = None
|
| 192 |
+
return messages, updated_state, file_path
|
| 193 |
+
|
| 194 |
+
def restart_conversation():
|
| 195 |
+
return [initial_message], {"step": 0, "answers": {}}, None
|
| 196 |
+
|
| 197 |
+
msg.submit(chat_logic, [msg, state], [chatbot, state, file_output])
|
| 198 |
+
restart_button.click(restart_conversation, outputs=[chatbot, state, file_output])
|
| 199 |
+
|
| 200 |
+
demo.launch(show_api=False)
|
| 201 |
|
|
|
|
|
|
|
| 202 |
...
|
| 203 |
|
| 204 |
stored_messages = [initial_message]
|