""" ProVerBs Legal AI - Integrated Landing Page with AI Legal Chatbot Incorporates your specialized AI Legal Chatbot with multiple modes """ import gradio as gr from huggingface_hub import InferenceClient import json import os from datetime import datetime from typing import Dict, List, Optional class AILegalChatbotIntegration: """ Integration of your AI Legal Chatbot into Gradio Supports all specialized modes from your original chatbot """ def __init__(self): self.specialized_modes = { "navigation": "Application Navigation Guide", "general": "General Legal Assistant", "document_validation": "Document Validator", "legal_research": "Legal Research Assistant", "etymology": "Legal Etymology Lookup", "case_management": "Case Management Helper", "regulatory_updates": "Regulatory Update Monitor" } # Application features from your original chatbot self.app_features = { "Legal Action Advisor": { "description": "Get personalized recommendations for seeking justice and remedy", "features": ["AI-powered action recommendations", "Case type analysis", "Timeline planning"] }, "Document Analysis": { "description": "Upload and analyze legal documents with AI-powered insights", "features": ["OCR text extraction", "Multi-format support", "AI analysis"] }, "Legal Research": { "description": "Comprehensive legal research tools and databases", "features": ["Multiple legal databases", "Case law research", "Statutory analysis"] }, "Communications": { "description": "Integrated communication system with SMS, email, and phone", "features": ["Twilio integration", "Legal alerts", "Case reminders"] }, "Document Generation": { "description": "AI-powered legal document creation and templates", "features": ["Smart templates", "Custom document builder", "Legal form generation"] } } def get_mode_system_prompt(self, mode: str) -> str: """Get specialized system prompt based on mode""" prompts = { "navigation": """You are a ProVerBs Application Navigation Guide. Help users navigate the application's features: **Available Features:** - Legal Action Advisor: Get recommendations for seeking justice - Document Analysis: Upload and analyze legal documents - Legal Research: Access comprehensive legal databases - Communications: SMS, email, and phone integration - Document Generation: Create legal documents with AI Guide users to the right features and explain how to use them effectively.""", "general": """You are a General Legal Assistant for ProVerBs Legal AI Platform. Provide accurate legal information while noting that you cannot provide legal advice. Always recommend consulting with a licensed attorney for specific legal matters. Be professional, thorough, and cite relevant legal principles when possible.""", "document_validation": """You are a Document Validator. Analyze legal documents for: - Completeness and required elements - Legal terminology accuracy - Structural integrity - Common issues and red flags Provide specific feedback on document quality and validity.""", "legal_research": """You are a Legal Research Assistant. Help users: - Find relevant case law and precedents - Understand statutes and regulations - Research legal principles and concepts - Cite authoritative legal sources Provide comprehensive research guidance.""", "etymology": """You are a Legal Etymology Expert. Explain the origins and meanings of legal terms: - Latin and historical roots - Evolution of legal terminology - Modern usage and interpretation - Related legal concepts Make legal language accessible and understandable.""", "case_management": """You are a Case Management Helper. Assist with: - Organizing case information - Tracking deadlines and milestones - Managing documents and evidence - Coordinating case activities Provide practical case management advice.""", "regulatory_updates": """You are a Regulatory Update Monitor. Keep users informed about: - Recent legal and regulatory changes - Industry-specific compliance updates - Important legislative developments - Impact analysis of new regulations Provide timely and relevant regulatory information.""" } return prompts.get(mode, prompts["general"]) def format_navigation_response(self, query: str) -> str: """Format response for navigation queries""" query_lower = query.lower() # Feature recommendations based on query recommendations = [] if any(word in query_lower for word in ["document", "contract", "agreement", "analyze"]): recommendations.append("đ **Document Analysis** - Upload and analyze your documents") if any(word in query_lower for word in ["research", "case", "law", "statute"]): recommendations.append("đ **Legal Research** - Access comprehensive legal databases") if any(word in query_lower for word in ["action", "remedy", "justice", "sue"]): recommendations.append("âī¸ **Legal Action Advisor** - Get recommendations for your situation") if any(word in query_lower for word in ["create", "generate", "template", "form"]): recommendations.append("đ **Document Generation** - Create legal documents with AI") if any(word in query_lower for word in ["communicate", "message", "sms", "email"]): recommendations.append("đ§ **Communications** - Integrated messaging system") if recommendations: return "### I can help you with these features:\n\n" + "\n".join(recommendations) + "\n\n**What would you like to explore?**" return None def respond_with_mode( message, history: list, mode: str, max_tokens: int, temperature: float, top_p: float, hf_token: gr.OAuthToken | None = None ): """ Generate AI response based on selected mode """ chatbot_integration = AILegalChatbotIntegration() # Get mode-specific system prompt system_message = chatbot_integration.get_mode_system_prompt(mode) # Check for navigation-specific responses if mode == "navigation": nav_response = chatbot_integration.format_navigation_response(message) if nav_response: yield nav_response return # Use HF Inference API token = hf_token.token if hf_token else None client = InferenceClient(token=token, model="meta-llama/Llama-3.3-70B-Instruct") # Prepare messages messages = [{"role": "system", "content": system_message}] for user_msg, assistant_msg in history: if user_msg: messages.append({"role": "user", "content": user_msg}) if assistant_msg: messages.append({"role": "assistant", "content": assistant_msg}) messages.append({"role": "user", "content": message}) # Stream response response = "" try: for message_chunk in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): if message_chunk.choices and message_chunk.choices[0].delta.content: token = message_chunk.choices[0].delta.content response += token yield response except Exception as e: yield f"Error: {str(e)}" # Custom CSS custom_css = """ .gradio-container { max-width: 1200px !important; } .header-section { text-align: center; padding: 40px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 12px; margin-bottom: 30px; } .header-section h1 { font-size: 3rem; margin-bottom: 10px; font-weight: 700; } .mode-selector { font-size: 1.1rem !important; font-weight: 600 !important; padding: 12px !important; } .tab-nav button { font-size: 16px; font-weight: 600; } .feature-card { border: 2px solid #e0e0e0; border-radius: 12px; padding: 20px; margin: 10px; background: #f8f9fa; } """ # Create the main application with gr.Blocks( theme=gr.themes.Soft( primary_hue="purple", secondary_hue="blue", ), css=custom_css, title="ProVerBs Legal AI Platform" ) as demo: # Header gr.HTML("""
Lawful vs. Legal: Dual Analysis "Adappt'plication"
Professional Legal AI System | Multi-Module Platform | Powered by Advanced AI
âī¸ ProVerBs Legal AI Platform | Version 1.0.0
Hugging Face | GitHub | Documentation
â ī¸ Disclaimer: This AI provides general legal information only. Consult with a licensed attorney for specific legal matters.
Š 2024 ProVerBs Legal AI. Built with â¤ī¸ for legal professionals worldwide.