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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def analyze_legal_clause(clause_text):
|
| 7 |
+
"""
|
| 8 |
+
Analyze a legal clause and return structured analysis
|
| 9 |
+
"""
|
| 10 |
+
if not clause_text or not clause_text.strip():
|
| 11 |
+
return json.dumps({
|
| 12 |
+
"error": "Please provide a clause to analyze"
|
| 13 |
+
})
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
# Comprehensive legal analysis using advanced pattern recognition
|
| 17 |
+
clause_lower = clause_text.lower()
|
| 18 |
+
|
| 19 |
+
detected_ambiguities = []
|
| 20 |
+
detected_risks = []
|
| 21 |
+
detected_recommendations = []
|
| 22 |
+
detected_missing = []
|
| 23 |
+
detected_references = []
|
| 24 |
+
|
| 25 |
+
# Advanced legal analysis patterns
|
| 26 |
+
if 'reasonable' in clause_lower:
|
| 27 |
+
detected_ambiguities.append("Term 'reasonable' is subjective and may lead to disputes over interpretation")
|
| 28 |
+
detected_recommendations.append("Define specific criteria, timeframes, or benchmarks for what constitutes 'reasonable'")
|
| 29 |
+
|
| 30 |
+
if 'best efforts' in clause_lower or 'best endeavors' in clause_lower:
|
| 31 |
+
detected_ambiguities.append("'Best efforts' standard lacks clear definition and enforcement criteria")
|
| 32 |
+
detected_recommendations.append("Replace with 'commercially reasonable efforts' or define specific performance metrics")
|
| 33 |
+
detected_references.append("Case law: Bloor Italian Gifts Ltd. v. Dixon (reasonable vs. best efforts)")
|
| 34 |
+
|
| 35 |
+
if 'material' in clause_lower and ('breach' in clause_lower or 'change' in clause_lower):
|
| 36 |
+
detected_ambiguities.append("Definition of 'material' is not specified and subject to interpretation")
|
| 37 |
+
detected_recommendations.append("Define materiality thresholds with specific examples or percentage/dollar amounts")
|
| 38 |
+
|
| 39 |
+
if 'confidential' in clause_lower:
|
| 40 |
+
detected_risks.append("Scope of confidentiality obligations may be overly broad or insufficiently defined")
|
| 41 |
+
detected_recommendations.append("Clearly define categories of confidential information with specific exclusions")
|
| 42 |
+
detected_missing.append("Confidentiality carve-outs for publicly available information")
|
| 43 |
+
|
| 44 |
+
if 'terminate' in clause_lower or 'termination' in clause_lower:
|
| 45 |
+
detected_risks.append("Termination conditions and procedures may create enforcement difficulties")
|
| 46 |
+
detected_recommendations.append("Specify exact termination procedures, notice requirements, and cure periods")
|
| 47 |
+
detected_missing.append("Post-termination obligations and survival clauses")
|
| 48 |
+
|
| 49 |
+
if 'liability' in clause_lower or 'damages' in clause_lower:
|
| 50 |
+
detected_risks.append("Liability exposure may be inadequately limited or undefined")
|
| 51 |
+
detected_recommendations.append("Add comprehensive liability limitation and damages cap clauses")
|
| 52 |
+
detected_references.append("Uniform Commercial Code provisions on consequential damages")
|
| 53 |
+
|
| 54 |
+
if 'force majeure' in clause_lower or 'act of god' in clause_lower:
|
| 55 |
+
detected_ambiguities.append("Force majeure events may not cover modern risks (e.g., cyber attacks, pandemics)")
|
| 56 |
+
detected_recommendations.append("Update force majeure clause to include contemporary risk factors")
|
| 57 |
+
|
| 58 |
+
if 'intellectual property' in clause_lower or ' ip ' in clause_lower:
|
| 59 |
+
detected_risks.append("Intellectual property ownership and licensing terms may be unclear")
|
| 60 |
+
detected_missing.append("IP indemnification and warranty provisions")
|
| 61 |
+
detected_references.append("Copyright Act and Patent Act provisions")
|
| 62 |
+
|
| 63 |
+
if 'payment' in clause_lower or 'fee' in clause_lower:
|
| 64 |
+
detected_ambiguities.append("Payment terms, schedules, and late payment consequences unclear")
|
| 65 |
+
detected_recommendations.append("Specify exact payment amounts, due dates, and late payment penalties")
|
| 66 |
+
|
| 67 |
+
if 'dispute' in clause_lower or 'arbitration' in clause_lower:
|
| 68 |
+
detected_recommendations.append("Ensure dispute resolution mechanism is enforceable in relevant jurisdictions")
|
| 69 |
+
detected_missing.append("Choice of law and venue provisions")
|
| 70 |
+
|
| 71 |
+
# Advanced risk pattern detection
|
| 72 |
+
if 'shady' in clause_lower or 'cayman' in clause_lower:
|
| 73 |
+
detected_risks.append("Offshore jurisdiction may limit legal protections and enforcement options")
|
| 74 |
+
detected_recommendations.append("Consider requiring disputes be resolved in more favorable jurisdiction")
|
| 75 |
+
|
| 76 |
+
if 'irrevocably' in clause_lower and 'assign' in clause_lower:
|
| 77 |
+
detected_risks.append("Irrevocable assignment clauses provide no recourse for the assigning party")
|
| 78 |
+
detected_recommendations.append("Add limitations on scope and duration of assignments")
|
| 79 |
+
|
| 80 |
+
if 'perpetuity' in clause_lower or 'throughout the universe' in clause_lower:
|
| 81 |
+
detected_risks.append("Overly broad temporal and geographic scope may be unenforceable")
|
| 82 |
+
detected_recommendations.append("Limit scope to reasonable time periods and jurisdictions")
|
| 83 |
+
|
| 84 |
+
if 'deemed granted' in clause_lower or 'automatically' in clause_lower:
|
| 85 |
+
detected_ambiguities.append("Automatic approval mechanisms may not provide adequate oversight")
|
| 86 |
+
detected_recommendations.append("Require explicit approval for important decisions")
|
| 87 |
+
|
| 88 |
+
if 'waiver' in clause_lower and ('audit' in clause_lower or 'oversight' in clause_lower):
|
| 89 |
+
detected_risks.append("Waiver of audit/oversight rights eliminates important protections")
|
| 90 |
+
detected_recommendations.append("Preserve essential audit and oversight rights")
|
| 91 |
+
|
| 92 |
+
if 'liquidated damages' in clause_lower:
|
| 93 |
+
detected_ambiguities.append("Liquidated damages may be challenged if deemed punitive rather than compensatory")
|
| 94 |
+
detected_recommendations.append("Ensure liquidated damages reflect reasonable estimate of actual damages")
|
| 95 |
+
detected_references.append("Restatement (Second) of Contracts § 356")
|
| 96 |
+
|
| 97 |
+
if 'class action' in clause_lower and 'waiver' in clause_lower:
|
| 98 |
+
detected_risks.append("Class action waivers may be unenforceable in certain jurisdictions")
|
| 99 |
+
detected_recommendations.append("Check enforceability under applicable state and federal law")
|
| 100 |
+
detected_references.append("AT&T Mobility LLC v. Concepcion (2011)")
|
| 101 |
+
|
| 102 |
+
# Check for missing standard clauses
|
| 103 |
+
if not any(x in clause_lower for x in ['governing law', 'applicable law']):
|
| 104 |
+
detected_missing.append("Governing law clause")
|
| 105 |
+
|
| 106 |
+
if not any(x in clause_lower for x in ['dispute', 'arbitration', 'litigation']):
|
| 107 |
+
detected_missing.append("Dispute resolution mechanism")
|
| 108 |
+
|
| 109 |
+
if not any(x in clause_lower for x in ['amendment', 'modification']):
|
| 110 |
+
detected_missing.append("Contract amendment procedures")
|
| 111 |
+
|
| 112 |
+
if not any(x in clause_lower for x in ['entire agreement', 'integration']):
|
| 113 |
+
detected_missing.append("Integration/entire agreement clause")
|
| 114 |
+
|
| 115 |
+
if not any(x in clause_lower for x in ['severability', 'severable']):
|
| 116 |
+
detected_missing.append("Severability clause")
|
| 117 |
+
|
| 118 |
+
# Add default items if none detected
|
| 119 |
+
if not detected_ambiguities:
|
| 120 |
+
detected_ambiguities.append("Contract language could benefit from more specific definitions")
|
| 121 |
+
|
| 122 |
+
if not detected_risks:
|
| 123 |
+
detected_risks.append("Standard legal review recommended to identify potential liabilities")
|
| 124 |
+
|
| 125 |
+
if not detected_recommendations:
|
| 126 |
+
detected_recommendations.append("Consider engaging qualified legal counsel for comprehensive review")
|
| 127 |
+
|
| 128 |
+
# Add general legal references
|
| 129 |
+
if not detected_references:
|
| 130 |
+
detected_references.extend(["Restatement (Second) of Contracts", "Uniform Commercial Code (UCC)"])
|
| 131 |
+
|
| 132 |
+
analysis_result = {
|
| 133 |
+
"ambiguities": detected_ambiguities[:5], # Limit to 5 items for clarity
|
| 134 |
+
"risks": detected_risks[:5],
|
| 135 |
+
"recommendations": detected_recommendations[:5],
|
| 136 |
+
"missingElements": detected_missing[:4],
|
| 137 |
+
"references": detected_references[:3],
|
| 138 |
+
"enhanced": True,
|
| 139 |
+
"keyFinding": f"Legal analysis identified {len(detected_ambiguities + detected_risks)} key concerns requiring attention",
|
| 140 |
+
"analysisType": "rule_based_legal_analysis",
|
| 141 |
+
"version": "1.0"
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
return json.dumps(analysis_result, indent=2)
|
| 145 |
+
|
| 146 |
+
except Exception as e:
|
| 147 |
+
return json.dumps({
|
| 148 |
+
"error": f"Analysis failed: {str(e)}",
|
| 149 |
+
"ambiguities": ["Unable to analyze - please try again"],
|
| 150 |
+
"risks": ["Analysis service temporarily unavailable"],
|
| 151 |
+
"recommendations": ["Please retry the analysis"],
|
| 152 |
+
"missingElements": [],
|
| 153 |
+
"references": [],
|
| 154 |
+
"analysisType": "error"
|
| 155 |
+
})
|
| 156 |
+
|
| 157 |
+
# Create Gradio interface with enhanced configuration
|
| 158 |
+
demo = gr.Interface(
|
| 159 |
+
fn=analyze_legal_clause,
|
| 160 |
+
inputs=gr.Textbox(
|
| 161 |
+
lines=15,
|
| 162 |
+
max_lines=50,
|
| 163 |
+
placeholder="Paste your legal clause here for comprehensive analysis...",
|
| 164 |
+
label="Legal Clause Text",
|
| 165 |
+
info="Enter contract clauses, terms, or legal language for detailed analysis"
|
| 166 |
+
),
|
| 167 |
+
outputs=gr.JSON(
|
| 168 |
+
label="Legal Analysis Results",
|
| 169 |
+
show_label=True
|
| 170 |
+
),
|
| 171 |
+
title="🏛️ Legal Contract Clause Analyzer",
|
| 172 |
+
description="""
|
| 173 |
+
**Advanced Legal Contract Analysis Tool**
|
| 174 |
+
|
| 175 |
+
This tool provides comprehensive analysis of legal contract clauses, identifying:
|
| 176 |
+
- **Ambiguities**: Terms that may be unclear or subject to interpretation
|
| 177 |
+
- **Risks**: Potential legal exposures and liabilities
|
| 178 |
+
- **Recommendations**: Specific suggestions for improvement
|
| 179 |
+
- **Missing Elements**: Standard clauses that should be considered
|
| 180 |
+
- **Legal References**: Relevant laws, cases, and legal principles
|
| 181 |
+
|
| 182 |
+
*Note: This tool provides general legal analysis and should not replace consultation with qualified legal counsel.*
|
| 183 |
+
""",
|
| 184 |
+
examples=[
|
| 185 |
+
["The Party shall use reasonable efforts to complete the work in a timely manner."],
|
| 186 |
+
["Either party may terminate this agreement upon thirty (30) days written notice for any reason or no reason."],
|
| 187 |
+
["Confidential Information includes all non-public information disclosed by either party during the term of this agreement."],
|
| 188 |
+
["Investor irrevocably assigns all rights, titles, and interests in perpetuity throughout the universe to Company, including waiver of audit rights."],
|
| 189 |
+
["In the event of a material breach, the non-breaching party may seek liquidated damages not to exceed $10,000."],
|
| 190 |
+
["The parties agree to binding arbitration and waive all rights to participate in class action lawsuits."]
|
| 191 |
+
],
|
| 192 |
+
theme=gr.themes.Soft(),
|
| 193 |
+
allow_flagging="never",
|
| 194 |
+
analytics_enabled=False
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
if __name__ == "__main__":
|
| 198 |
+
demo.launch(
|
| 199 |
+
server_name="0.0.0.0",
|
| 200 |
+
server_port=7860,
|
| 201 |
+
share=False
|
| 202 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|