Spaces:
No application file
No application file
Download agents/parse_agent.py from jaweria01/Legal_AI_Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/jaweria01/Legal_AI_Agent/resolve/main/agents/parse_agent.py
- Command line
-
hf download hf://spaces/jaweria01/Legal_AI_Agent/agents/parse_agent.py
-
curl -L -o parse_agent.py https://huggingface.co/spaces/jaweria01/Legal_AI_Agent/resolve/main/agents/parse_agent.py
1.15 kB
| # agents/parse_agent.py | |
| import re | |
| def extract_clauses_from_text(text): | |
| """ | |
| Takes full legal text and returns a list of clauses based on patterns like 'شق 1:', 'شق 2:' etc. | |
| """ | |
| # Urdu pattern for شق | |
| pattern = r"(شق[\s\d:]+)" | |
| # Split using regex | |
| parts = re.split(pattern, text) | |
| # Rebuild clean clause blocks | |
| clauses = [] | |
| for i in range(1, len(parts), 2): | |
| heading = parts[i].strip() | |
| body = parts[i + 1].strip() if (i + 1) < len(parts) else "" | |
| full_clause = f"{heading} {body}".strip() | |
| if len(full_clause) > 20: | |
| clauses.append(full_clause) | |
| return clauses | |
| # Test this code separately | |
| if __name__ == "__main__": | |
| sample_text = """ | |
| شق 1: کرایہ دار کو ہر ماہ کی 5 تاریخ تک کرایہ ادا کرنا ہوگا۔ | |
| شق 2: مکان خالی کرنے کے لیے 30 دن کا نوٹس دینا لازمی ہے۔ | |
| شق 3: مالک مکان بغیر اطلاع کے کرایہ نہیں بڑھا سکتا۔ | |
| """ | |
| extracted = extract_clauses_from_text(sample_text) | |
| for c in extracted: | |
| print("➡️", c) | |