Spaces:
Sleeping
Sleeping
testing 3
Browse files- backend/text_recog.py +28 -20
backend/text_recog.py
CHANGED
@@ -20,28 +20,36 @@ def extract_ktp_info(image_path, filename):
|
|
20 |
|
21 |
text = text.replace('\n\n\n', '\n').replace('\n\n', '\n').replace('\n', '\n')
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
city = re.search(r'PROVINSI\s+(.+?)\n(.+?)\n', text)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# if "WNI" in text:
|
43 |
-
# result["Kewarganegaraan"] = "WNI"
|
44 |
|
45 |
# convert_image_to_word(result, f'KTP {filename}')
|
46 |
|
47 |
-
return
|
|
|
20 |
|
21 |
text = text.replace('\n\n\n', '\n').replace('\n\n', '\n').replace('\n', '\n')
|
22 |
|
23 |
+
match = re.search(r'Berlaku Hingga\n(.*?)\nGol\. Darah', text, re.DOTALL)
|
24 |
+
|
25 |
+
if match:
|
26 |
+
extracted_text = match.group(1)
|
27 |
+
lines = [
|
28 |
+
re.sub(r'^(:|\d+)?\s*', '', line.strip())
|
29 |
+
for line in extracted_text.strip().split('\n')
|
30 |
+
if line.strip()
|
31 |
+
]
|
32 |
+
print("Hasil List Bersih:")
|
33 |
+
print(lines)
|
34 |
+
|
35 |
city = re.search(r'PROVINSI\s+(.+?)\n(.+?)\n', text)
|
36 |
|
37 |
+
result = {
|
38 |
+
"nik" : lines[0],
|
39 |
+
"nama" : lines[1],
|
40 |
+
"tempat_tgl_lahir" : lines[2],
|
41 |
+
"jenis_kelamin" : lines[3],
|
42 |
+
"alamat" : lines[4],
|
43 |
+
"rt_rw" : lines[5],
|
44 |
+
"kel/desa" : lines[6],
|
45 |
+
"kecamatan" : lines[7],
|
46 |
+
"provinsi" : lines[13],
|
47 |
+
"kab/kota" : lines[14],
|
48 |
+
"agama" : lines[8],
|
49 |
+
"kewarganegaraan" : lines[10],
|
50 |
+
"pekerjaan" : lines[9],
|
51 |
+
}
|
|
|
|
|
|
|
52 |
|
53 |
# convert_image_to_word(result, f'KTP {filename}')
|
54 |
|
55 |
+
return result
|