import gradio as gr import os import asyncio try: from api import consult_logic, generate_doc_logic print("✅ Logic successfully connected from api.py") except Exception as e: error_text = str(e) print(f"❌ IMPORT/LOGIC ERROR: {error_text}") async def consult_logic(msg): return {"content": f"System Logic Error: {error_text}"} async def generate_doc_logic(msg): return {"content": f"System Logic Error: {error_text}"} async def main_interface(user_text): if not user_text: return None, "" doc_keywords = ["draft", "generate", "create", "contract", "agreement", "clause", "policy", "legal form"] is_doc = any(kw in user_text.lower() for kw in doc_keywords) and len(user_text) > 12 try: if is_doc: # TODO: Document generation logic (Coming Soon) return None, "🛠️ **Document Generation feature is coming soon!**\n\nCurrently, I can only provide legal consultations regarding GDPR. Please try asking a question like: *'What are the requirements for a Privacy Policy?'*" else: result = await consult_logic(user_text) return None, result.get("content", "") except Exception as e: return None, f"⚠️ System Error: {str(e)}" async def respond(message, history): if history is None: history = [] _, response_text = await main_interface(message) history.append({"role": "user", "content": message}) history.append({"role": "assistant", "content": response_text}) return "", history css_code = """ """ with gr.Blocks(title="LexGuard EU") as demo: gr.HTML(css_code) with gr.Column(elem_id="app-layout"): gr.HTML('
Next-Gen GDPR & EU Law Intelligence
') msg = gr.Textbox( render=False, elem_id="chat-input", placeholder="Ask about GDPR compliance or legal...", show_label=False, container=False ) with gr.Row(elem_id="suggestions-row"): btn_doc = gr.Button("📄 Generate Document (Soon)", elem_classes=["suggestion-btn", "soon-btn"], interactive=False) btn_law = gr.Button("⚖️ Legal Analysis", elem_classes="suggestion-btn") btn_cons = gr.Button("🎓 GDPR Consultation", elem_classes="suggestion-btn") btn_claim = gr.Button("📩 Complaints / Claims", elem_classes="suggestion-btn") examples_container = gr.Column() chatbot = gr.Chatbot( elem_id="gpt-chat", show_label=False, height=450, ) with gr.Row(elem_id="input-capsule"): msg = gr.Textbox( elem_id="chat-input", placeholder="Ask about GDPR compliance or legal procedures...", show_label=False, scale=10, container=False ) submit = gr.Button("↑", elem_id="send-btn", scale=0) with gr.Row(): with gr.Column(scale=1): gr.Examples( examples=[ ["What are the transparency obligations for high-risk AI?"], ["Explain Article 17 GDPR."], ["Cyber vulnerability reporting deadlines?"] ], inputs=msg, label=None, elem_id="compact-examples" ) gr.HTML("""
Disclaimer: AI can make mistakes. Verify important information.
Powered by DeepSeek-V3.2
""") btn_doc.click(lambda: "Help me draft a Privacy Policy for a startup: ", None, msg) btn_law.click(lambda: "Analyze GDPR requirements for data processing: ", None, msg) btn_cons.click(lambda: "What are the DPO's main responsibilities according to GDPR? ", None, msg) btn_claim.click(lambda: "How to file a data breach notification to the authority? ", None, msg) msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) submit.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) if __name__ == "__main__": abs_downloads_path = os.path.abspath("downloads") os.makedirs(abs_downloads_path, exist_ok=True) demo.launch(server_name="0.0.0.0", show_error=True)