Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,7 @@ ProofAssets: Real Estate Tokenizer (Heuristic Demo)
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
-
import re
|
| 7 |
-
import json
|
| 8 |
from typing import Dict, Any, List, Optional
|
| 9 |
from dateparser.search import search_dates
|
| 10 |
import gradio as gr
|
|
@@ -15,8 +14,7 @@ def _clean(s: str) -> str:
|
|
| 15 |
def extract_parties(text: str) -> Optional[List[str]]:
|
| 16 |
m = re.search(r"\bbetween\s+(.+?)\s+and\s+(.+?)(?:[,.;\n]| for\b)", text, re.I | re.S)
|
| 17 |
if m:
|
| 18 |
-
p1 = _clean(m.group(1))
|
| 19 |
-
p2 = _clean(m.group(2))
|
| 20 |
p1 = re.sub(r"^(?:the\s+)?(landlord|lessor|owner)\s*[:\-]*\s*", "", p1, flags=re.I)
|
| 21 |
p2 = re.sub(r"^(?:the\s+)?(tenant|lessee|occupant)\s*[:\-]*\s*", "", p2, flags=re.I)
|
| 22 |
return [p1, p2]
|
|
@@ -34,14 +32,13 @@ def extract_address(text: str) -> Optional[str]:
|
|
| 34 |
r"\baddress\s*[:\-]\s*(.+?)(?:[,.;\n])",
|
| 35 |
]:
|
| 36 |
m = re.search(pat, text, flags=re.I)
|
| 37 |
-
if m:
|
| 38 |
-
return _clean(m.group(1))
|
| 39 |
return None
|
| 40 |
|
| 41 |
def extract_term(text: str) -> Optional[str]:
|
| 42 |
m = re.search(r"(?:lease\s+term\s+is|for\s+a\s+term\s+of|term\s*[:\-])\s*(\d{1,3})\s*(month|months|year|years)", text, flags=re.I)
|
| 43 |
if m:
|
| 44 |
-
n = int(m.group(1))
|
| 45 |
return f"{n} years" if unit.startswith("year") else f"{n} months"
|
| 46 |
m = re.search(r"(\d{1,3})\s*-\s*month\s+term", text, flags=re.I)
|
| 47 |
if m: return f"{int(m.group(1))} months"
|
|
@@ -109,8 +106,7 @@ def extract_metadata(contract_text: str) -> Dict[str, Any]:
|
|
| 109 |
}
|
| 110 |
|
| 111 |
def summarize(metadata: Dict[str, Any]) -> str:
|
| 112 |
-
if "error" in metadata:
|
| 113 |
-
return f"**Error:** {metadata['error']}"
|
| 114 |
parts: List[str] = []
|
| 115 |
if metadata.get("parties"): parts.append(f"**Parties:** {', '.join(metadata['parties'])}")
|
| 116 |
if metadata.get("property_address"): parts.append(f"**Property:** {metadata['property_address']}")
|
|
@@ -154,5 +150,12 @@ with gr.Blocks(title="ProofAssets: Real Estate Tokenizer") as demo:
|
|
| 154 |
extract_btn.click(run_pipeline, inputs=inp, outputs=[summary_out, json_out])
|
| 155 |
clear_btn.click(lambda: ("", {}), None, [summary_out, json_out])
|
| 156 |
|
| 157 |
-
#
|
| 158 |
app = demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
+
import re, json, os
|
|
|
|
| 7 |
from typing import Dict, Any, List, Optional
|
| 8 |
from dateparser.search import search_dates
|
| 9 |
import gradio as gr
|
|
|
|
| 14 |
def extract_parties(text: str) -> Optional[List[str]]:
|
| 15 |
m = re.search(r"\bbetween\s+(.+?)\s+and\s+(.+?)(?:[,.;\n]| for\b)", text, re.I | re.S)
|
| 16 |
if m:
|
| 17 |
+
p1, p2 = _clean(m.group(1)), _clean(m.group(2))
|
|
|
|
| 18 |
p1 = re.sub(r"^(?:the\s+)?(landlord|lessor|owner)\s*[:\-]*\s*", "", p1, flags=re.I)
|
| 19 |
p2 = re.sub(r"^(?:the\s+)?(tenant|lessee|occupant)\s*[:\-]*\s*", "", p2, flags=re.I)
|
| 20 |
return [p1, p2]
|
|
|
|
| 32 |
r"\baddress\s*[:\-]\s*(.+?)(?:[,.;\n])",
|
| 33 |
]:
|
| 34 |
m = re.search(pat, text, flags=re.I)
|
| 35 |
+
if m: return _clean(m.group(1))
|
|
|
|
| 36 |
return None
|
| 37 |
|
| 38 |
def extract_term(text: str) -> Optional[str]:
|
| 39 |
m = re.search(r"(?:lease\s+term\s+is|for\s+a\s+term\s+of|term\s*[:\-])\s*(\d{1,3})\s*(month|months|year|years)", text, flags=re.I)
|
| 40 |
if m:
|
| 41 |
+
n, unit = int(m.group(1)), m.group(2).lower()
|
| 42 |
return f"{n} years" if unit.startswith("year") else f"{n} months"
|
| 43 |
m = re.search(r"(\d{1,3})\s*-\s*month\s+term", text, flags=re.I)
|
| 44 |
if m: return f"{int(m.group(1))} months"
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
def summarize(metadata: Dict[str, Any]) -> str:
|
| 109 |
+
if "error" in metadata: return f"**Error:** {metadata['error']}"
|
|
|
|
| 110 |
parts: List[str] = []
|
| 111 |
if metadata.get("parties"): parts.append(f"**Parties:** {', '.join(metadata['parties'])}")
|
| 112 |
if metadata.get("property_address"): parts.append(f"**Property:** {metadata['property_address']}")
|
|
|
|
| 150 |
extract_btn.click(run_pipeline, inputs=inp, outputs=[summary_out, json_out])
|
| 151 |
clear_btn.click(lambda: ("", {}), None, [summary_out, json_out])
|
| 152 |
|
| 153 |
+
# Expose standard names for the runner
|
| 154 |
app = demo
|
| 155 |
+
gradio_app = demo
|
| 156 |
+
|
| 157 |
+
# As a fallback, explicitly launch if executed directly (works fine on Spaces too)
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
demo.queue()
|
| 160 |
+
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", "7860")))
|
| 161 |
+
|