Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +25 -20
Gradio_UI.py
CHANGED
|
@@ -82,31 +82,30 @@ def continue_conversation(user_input):
|
|
| 82 |
|
| 83 |
if conversation_state["step"] < len(conversation_state["questions"]):
|
| 84 |
next_question = conversation_state["questions"][conversation_state["step"]][1]
|
| 85 |
-
messages.append({"role": "assistant", "content": f"
|
| 86 |
return messages, None
|
| 87 |
else:
|
| 88 |
pdf_path = export_pdf(conversation_state["title"], conversation_state["answers"], lang=conversation_state["lang"])
|
| 89 |
messages.append({"role": "assistant", "content": "✅ Done! Your document is ready to download."})
|
| 90 |
return messages, pdf_path
|
| 91 |
|
| 92 |
-
# ===
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
display: none !important;
|
| 106 |
-
}
|
| 107 |
"""
|
| 108 |
-
|
| 109 |
-
|
|
|
|
| 110 |
gr.Markdown("""
|
| 111 |
### 🔒 GDPR Notice
|
| 112 |
This assistant does not store any personal data.
|
|
@@ -114,6 +113,8 @@ with gr.Blocks(
|
|
| 114 |
You are responsible for the accuracy and legality of the information submitted.
|
| 115 |
""")
|
| 116 |
|
|
|
|
|
|
|
| 117 |
with gr.Row():
|
| 118 |
reg_dropdown = gr.Dropdown(
|
| 119 |
choices=list(DOCUMENT_TO_MODULE.keys()),
|
|
@@ -138,11 +139,15 @@ with gr.Blocks(
|
|
| 138 |
reg_dropdown.change(update_doc_dropdown, inputs=reg_dropdown, outputs=doc_dropdown)
|
| 139 |
|
| 140 |
start_btn = gr.Button("🚀 Start")
|
| 141 |
-
chatbox = gr.Chatbot(label="🧑⚖️ Legalbot", value=[], type="messages"
|
| 142 |
user_input = gr.Textbox(label="Your answer", placeholder="Type your answer and press Enter")
|
| 143 |
pdf_output = gr.File(label="Download PDF", visible=True)
|
| 144 |
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
|
| 147 |
user_input.submit(lambda: "", None, user_input)
|
| 148 |
|
|
|
|
| 82 |
|
| 83 |
if conversation_state["step"] < len(conversation_state["questions"]):
|
| 84 |
next_question = conversation_state["questions"][conversation_state["step"]][1]
|
| 85 |
+
messages.append({"role": "assistant", "content": f"🧐 {next_question}"})
|
| 86 |
return messages, None
|
| 87 |
else:
|
| 88 |
pdf_path = export_pdf(conversation_state["title"], conversation_state["answers"], lang=conversation_state["lang"])
|
| 89 |
messages.append({"role": "assistant", "content": "✅ Done! Your document is ready to download."})
|
| 90 |
return messages, pdf_path
|
| 91 |
|
| 92 |
+
# === Custom CSS for Cleanup ===
|
| 93 |
+
def get_custom_css():
|
| 94 |
+
return """
|
| 95 |
+
<style>
|
| 96 |
+
footer,
|
| 97 |
+
a[href*='gradio.app'],
|
| 98 |
+
a[href*='huggingface.co'],
|
| 99 |
+
button[aria-label='Share'],
|
| 100 |
+
button[data-testid='share-button'],
|
| 101 |
+
button[title='Share'] {
|
| 102 |
+
display: none !important;
|
| 103 |
+
}
|
| 104 |
+
</style>
|
|
|
|
|
|
|
| 105 |
"""
|
| 106 |
+
|
| 107 |
+
# === Gradio Interface ===
|
| 108 |
+
with gr.Blocks(title="Regulatory Compliance Generator") as demo:
|
| 109 |
gr.Markdown("""
|
| 110 |
### 🔒 GDPR Notice
|
| 111 |
This assistant does not store any personal data.
|
|
|
|
| 113 |
You are responsible for the accuracy and legality of the information submitted.
|
| 114 |
""")
|
| 115 |
|
| 116 |
+
css_injector = gr.HTML(get_custom_css())
|
| 117 |
+
|
| 118 |
with gr.Row():
|
| 119 |
reg_dropdown = gr.Dropdown(
|
| 120 |
choices=list(DOCUMENT_TO_MODULE.keys()),
|
|
|
|
| 139 |
reg_dropdown.change(update_doc_dropdown, inputs=reg_dropdown, outputs=doc_dropdown)
|
| 140 |
|
| 141 |
start_btn = gr.Button("🚀 Start")
|
| 142 |
+
chatbox = gr.Chatbot(label="🧑⚖️ Legalbot", value=[], type="messages")
|
| 143 |
user_input = gr.Textbox(label="Your answer", placeholder="Type your answer and press Enter")
|
| 144 |
pdf_output = gr.File(label="Download PDF", visible=True)
|
| 145 |
|
| 146 |
+
def start_conversation_and_inject_css(reg, doc):
|
| 147 |
+
css_injector.update(get_custom_css())
|
| 148 |
+
return start_conversation(reg, doc)
|
| 149 |
+
|
| 150 |
+
start_btn.click(start_conversation_and_inject_css, inputs=[reg_dropdown, doc_dropdown], outputs=chatbox)
|
| 151 |
user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
|
| 152 |
user_input.submit(lambda: "", None, user_input)
|
| 153 |
|