restore analiza
This commit is contained in:
15
app.py
15
app.py
@@ -365,6 +365,7 @@ def preprocess_image_for_tesseract(pil_image):
|
||||
|
||||
|
||||
def extract_total_tesseract(image):
|
||||
|
||||
text = pytesseract.image_to_string(image, lang="pol", config="--psm 6")
|
||||
lines = text.splitlines()
|
||||
candidates = []
|
||||
@@ -403,21 +404,19 @@ def extract_total_tesseract(image):
|
||||
except:
|
||||
continue
|
||||
|
||||
# Rozszerzone słowa kluczowe
|
||||
keywords = r"sum[aąo]?|razem|zapłat[ay]?|sprzedaż|opodatk|należność|do zapłaty"
|
||||
|
||||
preferred = [val for val, line in candidates if re.search(keywords, line.lower())]
|
||||
preferred = [
|
||||
val
|
||||
for val, line in candidates
|
||||
if re.search(r"sum[aąo]?|razem|zapłaty", line.lower())
|
||||
]
|
||||
|
||||
if preferred:
|
||||
max_val = round(max(preferred), 2)
|
||||
return max_val, lines
|
||||
|
||||
# Fallback: wybierz największą wartość jeśli jest sensowna
|
||||
if candidates:
|
||||
max_val = round(max([val for val, _ in candidates]), 2)
|
||||
# Jeśli np. większa niż 10 PLN, zakładamy że to może być suma końcowa
|
||||
if max_val >= 10:
|
||||
return max_val, lines
|
||||
return max_val, lines
|
||||
|
||||
return 0.0, lines
|
||||
|
||||
|
Reference in New Issue
Block a user