Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +10 -5
Gradio_UI.py
CHANGED
|
@@ -60,11 +60,14 @@ def start_conversation(reg, doc):
|
|
| 60 |
conversation_state["questions"] = module.get_questions()
|
| 61 |
conversation_state["tool"] = module
|
| 62 |
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
# === Continue Chat ===
|
| 66 |
def continue_conversation(user_input):
|
|
|
|
| 67 |
step = conversation_state["step"]
|
|
|
|
| 68 |
if step < len(conversation_state["questions"]):
|
| 69 |
key, question = conversation_state["questions"][step]
|
| 70 |
conversation_state["answers"][question] = user_input
|
|
@@ -73,10 +76,12 @@ def continue_conversation(user_input):
|
|
| 73 |
|
| 74 |
if conversation_state["step"] < len(conversation_state["questions"]):
|
| 75 |
next_question = conversation_state["questions"][conversation_state["step"]][1]
|
| 76 |
-
|
|
|
|
| 77 |
else:
|
| 78 |
pdf_path = export_pdf(conversation_state["title"], conversation_state["answers"], lang=conversation_state["lang"])
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
# === Gradio Interface ===
|
| 82 |
with gr.Blocks(title="Regulatory Compliance Generator") as demo:
|
|
@@ -94,12 +99,12 @@ with gr.Blocks(title="Regulatory Compliance Generator") as demo:
|
|
| 94 |
reg_dropdown.change(update_doc_dropdown, inputs=reg_dropdown, outputs=doc_dropdown)
|
| 95 |
|
| 96 |
start_btn = gr.Button("🚀 Start")
|
| 97 |
-
chatbox = gr.Chatbot(label="🧑⚖️ Legalbot", value=[])
|
| 98 |
user_input = gr.Textbox(label="Your answer", placeholder="Type your answer and press Enter")
|
| 99 |
pdf_output = gr.File(label="Download PDF", visible=True)
|
| 100 |
|
| 101 |
start_btn.click(start_conversation, inputs=[reg_dropdown, doc_dropdown], outputs=chatbox)
|
| 102 |
user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
|
| 103 |
-
user_input.submit(lambda: "", None, user_input)
|
| 104 |
|
| 105 |
demo.launch()
|
|
|
|
| 60 |
conversation_state["questions"] = module.get_questions()
|
| 61 |
conversation_state["tool"] = module
|
| 62 |
|
| 63 |
+
first_question = conversation_state["questions"][0][1]
|
| 64 |
+
return [{"role": "assistant", "content": f"📋 {first_question}"}]
|
| 65 |
|
| 66 |
# === Continue Chat ===
|
| 67 |
def continue_conversation(user_input):
|
| 68 |
+
messages = [{"role": "user", "content": user_input}]
|
| 69 |
step = conversation_state["step"]
|
| 70 |
+
|
| 71 |
if step < len(conversation_state["questions"]):
|
| 72 |
key, question = conversation_state["questions"][step]
|
| 73 |
conversation_state["answers"][question] = user_input
|
|
|
|
| 76 |
|
| 77 |
if conversation_state["step"] < len(conversation_state["questions"]):
|
| 78 |
next_question = conversation_state["questions"][conversation_state["step"]][1]
|
| 79 |
+
messages.append({"role": "assistant", "content": f"🧠 {next_question}"})
|
| 80 |
+
return messages, None
|
| 81 |
else:
|
| 82 |
pdf_path = export_pdf(conversation_state["title"], conversation_state["answers"], lang=conversation_state["lang"])
|
| 83 |
+
messages.append({"role": "assistant", "content": "✅ Done! Your document is ready to download."})
|
| 84 |
+
return messages, pdf_path
|
| 85 |
|
| 86 |
# === Gradio Interface ===
|
| 87 |
with gr.Blocks(title="Regulatory Compliance Generator") as demo:
|
|
|
|
| 99 |
reg_dropdown.change(update_doc_dropdown, inputs=reg_dropdown, outputs=doc_dropdown)
|
| 100 |
|
| 101 |
start_btn = gr.Button("🚀 Start")
|
| 102 |
+
chatbox = gr.Chatbot(label="🧑⚖️ Legalbot", value=[], type="messages") # <-- Updated to use new format
|
| 103 |
user_input = gr.Textbox(label="Your answer", placeholder="Type your answer and press Enter")
|
| 104 |
pdf_output = gr.File(label="Download PDF", visible=True)
|
| 105 |
|
| 106 |
start_btn.click(start_conversation, inputs=[reg_dropdown, doc_dropdown], outputs=chatbox)
|
| 107 |
user_input.submit(continue_conversation, inputs=user_input, outputs=[chatbox, pdf_output])
|
| 108 |
+
user_input.submit(lambda: "", None, user_input) # Clear input
|
| 109 |
|
| 110 |
demo.launch()
|