Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,10 @@ import re
|
|
| 2 |
import json
|
| 3 |
from typing import Dict, Any
|
| 4 |
import dateparser
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
|
|
|
|
| 7 |
# ---------- Heuristic extractors (no ML) ----------
|
| 8 |
|
| 9 |
def _clean(s: str) -> str:
|
|
@@ -55,20 +57,19 @@ def extract_term(text: str):
|
|
| 55 |
return f"{int(m.group(1))} months"
|
| 56 |
return None
|
| 57 |
|
| 58 |
-
|
| 59 |
# Try to find the first plausible date near "commencing/starting/effective"
|
| 60 |
window = re.search(r'(?:commencing|starting|effective)\s+on\s+(.{0,60})', text, flags=re.I)
|
| 61 |
candidates = []
|
| 62 |
if window:
|
| 63 |
-
parsed =
|
| 64 |
if parsed:
|
| 65 |
candidates.extend([d for _, d in parsed])
|
| 66 |
if not candidates:
|
| 67 |
-
parsed =
|
| 68 |
if parsed:
|
| 69 |
candidates.extend([d for _, d in parsed])
|
| 70 |
if candidates:
|
| 71 |
-
# Return earliest found (often the start date)
|
| 72 |
dt = sorted(candidates)[0]
|
| 73 |
return dt.strftime('%Y-%m-%d')
|
| 74 |
return None
|
|
|
|
| 2 |
import json
|
| 3 |
from typing import Dict, Any
|
| 4 |
import dateparser
|
| 5 |
+
from dateparser.search import search_dates # 👈 ADD THIS
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
+
|
| 9 |
# ---------- Heuristic extractors (no ML) ----------
|
| 10 |
|
| 11 |
def _clean(s: str) -> str:
|
|
|
|
| 57 |
return f"{int(m.group(1))} months"
|
| 58 |
return None
|
| 59 |
|
| 60 |
+
ef extract_start_date(text: str):
|
| 61 |
# Try to find the first plausible date near "commencing/starting/effective"
|
| 62 |
window = re.search(r'(?:commencing|starting|effective)\s+on\s+(.{0,60})', text, flags=re.I)
|
| 63 |
candidates = []
|
| 64 |
if window:
|
| 65 |
+
parsed = search_dates(window.group(0))
|
| 66 |
if parsed:
|
| 67 |
candidates.extend([d for _, d in parsed])
|
| 68 |
if not candidates:
|
| 69 |
+
parsed = search_dates(text)
|
| 70 |
if parsed:
|
| 71 |
candidates.extend([d for _, d in parsed])
|
| 72 |
if candidates:
|
|
|
|
| 73 |
dt = sorted(candidates)[0]
|
| 74 |
return dt.strftime('%Y-%m-%d')
|
| 75 |
return None
|