Update app.py
Browse files
app.py
CHANGED
|
@@ -31,20 +31,20 @@ STATEMENT_DIR = Path(__file__).parent / "sample_statements"
|
|
| 31 |
analyzer = None
|
| 32 |
model_load_error: Optional[str] = None
|
| 33 |
|
|
|
|
|
|
|
| 34 |
try:
|
| 35 |
from serving.inference import ContractAnalyzer # type: ignore
|
|
|
|
| 36 |
|
| 37 |
analyzer = ContractAnalyzer(model_path=MODEL_PATH)
|
|
|
|
| 38 |
print(f"Model loaded successfully: {MODEL_PATH}")
|
| 39 |
except Exception as e:
|
| 40 |
model_load_error = str(e)
|
| 41 |
print(f"WARNING: Model failed to load: {e}")
|
| 42 |
print("Demo is running in preview mode — analysis will return a placeholder response.")
|
| 43 |
|
| 44 |
-
# BankStatementAnalyzer reuses the loaded ContractAnalyzer pipeline
|
| 45 |
-
from serving.bank_statement import BankStatementAnalyzer # type: ignore
|
| 46 |
-
bank_analyzer = BankStatementAnalyzer(contract_analyzer=analyzer)
|
| 47 |
-
|
| 48 |
# ---------------------------------------------------------------------------
|
| 49 |
# Sample contract content
|
| 50 |
# ---------------------------------------------------------------------------
|
|
@@ -159,6 +159,8 @@ def _get_statement_text(
|
|
| 159 |
Priority: PDF > CSV > paste text.
|
| 160 |
"""
|
| 161 |
if pdf_file is not None:
|
|
|
|
|
|
|
| 162 |
try:
|
| 163 |
text = bank_analyzer.extract_text_from_pdf(pdf_file)
|
| 164 |
if not text.strip():
|
|
@@ -168,6 +170,8 @@ def _get_statement_text(
|
|
| 168 |
return "", f"PDF extraction error: {e}"
|
| 169 |
|
| 170 |
if csv_file is not None:
|
|
|
|
|
|
|
| 171 |
try:
|
| 172 |
text = bank_analyzer.parse_csv(csv_file)
|
| 173 |
return text, ""
|
|
@@ -1056,4 +1060,4 @@ with gr.Blocks(
|
|
| 1056 |
|
| 1057 |
|
| 1058 |
if __name__ == "__main__":
|
| 1059 |
-
demo.launch(show_error=True)
|
|
|
|
| 31 |
analyzer = None
|
| 32 |
model_load_error: Optional[str] = None
|
| 33 |
|
| 34 |
+
bank_analyzer = None
|
| 35 |
+
|
| 36 |
try:
|
| 37 |
from serving.inference import ContractAnalyzer # type: ignore
|
| 38 |
+
from serving.bank_statement import BankStatementAnalyzer # type: ignore
|
| 39 |
|
| 40 |
analyzer = ContractAnalyzer(model_path=MODEL_PATH)
|
| 41 |
+
bank_analyzer = BankStatementAnalyzer(contract_analyzer=analyzer)
|
| 42 |
print(f"Model loaded successfully: {MODEL_PATH}")
|
| 43 |
except Exception as e:
|
| 44 |
model_load_error = str(e)
|
| 45 |
print(f"WARNING: Model failed to load: {e}")
|
| 46 |
print("Demo is running in preview mode — analysis will return a placeholder response.")
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# ---------------------------------------------------------------------------
|
| 49 |
# Sample contract content
|
| 50 |
# ---------------------------------------------------------------------------
|
|
|
|
| 159 |
Priority: PDF > CSV > paste text.
|
| 160 |
"""
|
| 161 |
if pdf_file is not None:
|
| 162 |
+
if bank_analyzer is None:
|
| 163 |
+
return "", "Model not loaded — PDF extraction unavailable."
|
| 164 |
try:
|
| 165 |
text = bank_analyzer.extract_text_from_pdf(pdf_file)
|
| 166 |
if not text.strip():
|
|
|
|
| 170 |
return "", f"PDF extraction error: {e}"
|
| 171 |
|
| 172 |
if csv_file is not None:
|
| 173 |
+
if bank_analyzer is None:
|
| 174 |
+
return "", "Model not loaded — CSV parsing unavailable."
|
| 175 |
try:
|
| 176 |
text = bank_analyzer.parse_csv(csv_file)
|
| 177 |
return text, ""
|
|
|
|
| 1060 |
|
| 1061 |
|
| 1062 |
if __name__ == "__main__":
|
| 1063 |
+
demo.launch(show_error=True)
|