Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import torch
|
2 |
-
from transformers import
|
3 |
import spacy
|
4 |
from typing import Dict, List, Tuple
|
5 |
import sqlite3
|
@@ -8,14 +8,14 @@ import uuid
|
|
8 |
|
9 |
class AccountingNLP:
|
10 |
def __init__(self):
|
11 |
-
#
|
12 |
-
self.tokenizer =
|
13 |
-
self.model =
|
14 |
-
#
|
15 |
self.nlp = spacy.load("en_core_web_sm")
|
16 |
-
# Initialize accounting knowledge base
|
17 |
self.accounting_rules = self.load_accounting_rules()
|
18 |
-
|
|
|
19 |
self.create_tables()
|
20 |
|
21 |
def load_accounting_rules(self) -> Dict:
|
@@ -118,6 +118,7 @@ class AccountingNLP:
|
|
118 |
total_credit = sum(entry['credit'] for entry in entries)
|
119 |
|
120 |
if total_debit != total_credit:
|
|
|
121 |
return False, "Debits and credits must balance"
|
122 |
if not entries:
|
123 |
return False, "No valid entries generated"
|
|
|
1 |
import torch
|
2 |
+
from transformers import DistilBertTokenizer, DistilBertModel
|
3 |
import spacy
|
4 |
from typing import Dict, List, Tuple
|
5 |
import sqlite3
|
|
|
8 |
|
9 |
class AccountingNLP:
|
10 |
def __init__(self):
|
11 |
+
# Use DistilBERT for lower memory usage
|
12 |
+
self.tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
|
13 |
+
self.model = DistilBertModel.from_pretrained('distilbert-base-uncased')
|
14 |
+
# Load spaCy model
|
15 |
self.nlp = spacy.load("en_core_web_sm")
|
|
|
16 |
self.accounting_rules = self.load_accounting_rules()
|
17 |
+
# Use /app for SQLite to ensure write permissions
|
18 |
+
self.connection = sqlite3.connect('/app/accounting_db.sqlite')
|
19 |
self.create_tables()
|
20 |
|
21 |
def load_accounting_rules(self) -> Dict:
|
|
|
118 |
total_credit = sum(entry['credit'] for entry in entries)
|
119 |
|
120 |
if total_debit != total_credit:
|
121 |
+
return FalseV2 = False
|
122 |
return False, "Debits and credits must balance"
|
123 |
if not entries:
|
124 |
return False, "No valid entries generated"
|