Spaces:
Sleeping
Sleeping
Update backup_features.py
Browse files- backup_features.py +53 -51
backup_features.py
CHANGED
|
@@ -1,52 +1,54 @@
|
|
| 1 |
# backup_features.py
|
| 2 |
-
#
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
for
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
return [
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
| 1 |
# backup_features.py
|
| 2 |
+
# --------------------------------------------------------------
|
| 3 |
+
# Light-weight rule-based feature implementations
|
| 4 |
+
# (HuggingFace CPU-safe, no ML models)
|
| 5 |
+
# --------------------------------------------------------------
|
| 6 |
+
|
| 7 |
+
import re
|
| 8 |
+
|
| 9 |
+
def named_entity_recognition(text):
|
| 10 |
+
parties = re.findall(r"\b[A-Z][a-z]+(?: [A-Z][a-z]+)*\b", text)
|
| 11 |
+
dates = re.findall(r"\b\d{4}\b", text)
|
| 12 |
+
amounts = re.findall(r"\$\d+(?:,\d{3})*", text)
|
| 13 |
+
terms = re.findall(r"\b[A-Za-z]{6,}\b", text)
|
| 14 |
+
|
| 15 |
+
return {
|
| 16 |
+
"parties": list(set(parties[:10])),
|
| 17 |
+
"dates": list(set(dates)),
|
| 18 |
+
"amounts": list(set(amounts)),
|
| 19 |
+
"terms": list(set(terms[:20]))
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def clause_extraction(text):
|
| 24 |
+
clauses = re.split(r"\n+|\.\s+", text)
|
| 25 |
+
clauses = [c.strip() for c in clauses if len(c.strip()) > 40]
|
| 26 |
+
return clauses[:12]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def risk_analysis(text):
|
| 30 |
+
risks = [
|
| 31 |
+
"Very broad confidentiality definitions.",
|
| 32 |
+
"Unlimited liability exposure.",
|
| 33 |
+
"One-sided termination rights.",
|
| 34 |
+
"Strict non-solicitation terms.",
|
| 35 |
+
"Very long survival period."
|
| 36 |
+
]
|
| 37 |
+
return risks[:5]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def fairness_assessment(text):
|
| 41 |
+
score = 40
|
| 42 |
+
return {"score": score, "company_power": 60}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def alternative_clauses():
|
| 46 |
+
return [
|
| 47 |
+
{"title": "Balanced Version", "frequency": 78, "text": "Both parties must mutually approve disclosure."},
|
| 48 |
+
{"title": "Standard Version", "frequency": 55, "text": "Confidential data must be protected for 2 years."},
|
| 49 |
+
{"title": "Strict Version", "frequency": 22, "text": "Party B must delete all data within 5 days."},
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def ai_contract_assistant(text):
|
| 54 |
+
return "You may request clarification of overly broad definitions or long-term obligations."
|