Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,41 @@
|
|
1 |
import os
|
2 |
-
os.environ["OMP_NUM_THREADS"] = "1" # Avoid multithread warning
|
3 |
|
4 |
import gradio as gr
|
5 |
from utils import extract_kyc_fields
|
6 |
|
7 |
def process_documents(files):
|
8 |
"""
|
9 |
-
Accepts multiple files, OCRs each, and returns a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
"""
|
11 |
if not files:
|
12 |
return {"error": "No file(s) uploaded."}
|
13 |
|
|
|
|
|
|
|
|
|
14 |
results = []
|
15 |
for f in files:
|
16 |
try:
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
results.append(res)
|
22 |
except Exception as e:
|
23 |
results.append({"error": f"OCR failed for {getattr(f, 'name', 'file')}: {str(e)}"})
|
24 |
-
|
25 |
return {"results": results}
|
26 |
|
27 |
with gr.Blocks(title="Smart KYC OCR") as demo:
|
@@ -29,7 +43,7 @@ with gr.Blocks(title="Smart KYC OCR") as demo:
|
|
29 |
"""
|
30 |
# 🧾 Smart KYC OCR Tool
|
31 |
Upload images of **Aadhaar** and/or **PAN** cards — multiple at once — and get structured KYC data instantly.
|
32 |
-
Powered by **PaddleOCR** and smart
|
33 |
|
34 |
---
|
35 |
"""
|
@@ -40,7 +54,7 @@ with gr.Blocks(title="Smart KYC OCR") as demo:
|
|
40 |
uploader = gr.File(
|
41 |
label="📤 Upload Aadhaar / PAN Image(s)",
|
42 |
file_types=[".jpg", ".jpeg", ".png"],
|
43 |
-
multiple
|
44 |
)
|
45 |
submit_btn = gr.Button("🔍 Extract KYC Info", variant="primary")
|
46 |
|
@@ -58,4 +72,5 @@ with gr.Blocks(title="Smart KYC OCR") as demo:
|
|
58 |
)
|
59 |
|
60 |
if __name__ == "__main__":
|
|
|
61 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
os.environ["OMP_NUM_THREADS"] = "1" # Avoid multithread warning from some BLAS libs
|
3 |
|
4 |
import gradio as gr
|
5 |
from utils import extract_kyc_fields
|
6 |
|
7 |
def process_documents(files):
|
8 |
"""
|
9 |
+
Accepts multiple files, OCRs each, and returns a single JSON payload:
|
10 |
+
{
|
11 |
+
"results": [
|
12 |
+
{ ...result for file 1..., "source_file": "name1.png" },
|
13 |
+
{ ...result for file 2..., "source_file": "name2.jpg" },
|
14 |
+
...
|
15 |
+
]
|
16 |
+
}
|
17 |
"""
|
18 |
if not files:
|
19 |
return {"error": "No file(s) uploaded."}
|
20 |
|
21 |
+
# gr.File may return a single object or a list depending on Gradio version.
|
22 |
+
if not isinstance(files, list):
|
23 |
+
files = [files]
|
24 |
+
|
25 |
results = []
|
26 |
for f in files:
|
27 |
try:
|
28 |
+
fp = getattr(f, "name", None) or getattr(f, "path", None)
|
29 |
+
if not fp:
|
30 |
+
results.append({"error": "Could not read uploaded file path."})
|
31 |
+
continue
|
32 |
+
|
33 |
+
res = extract_kyc_fields(fp)
|
34 |
+
res["source_file"] = os.path.basename(fp)
|
35 |
results.append(res)
|
36 |
except Exception as e:
|
37 |
results.append({"error": f"OCR failed for {getattr(f, 'name', 'file')}: {str(e)}"})
|
38 |
+
|
39 |
return {"results": results}
|
40 |
|
41 |
with gr.Blocks(title="Smart KYC OCR") as demo:
|
|
|
43 |
"""
|
44 |
# 🧾 Smart KYC OCR Tool
|
45 |
Upload images of **Aadhaar** and/or **PAN** cards — multiple at once — and get structured KYC data instantly.
|
46 |
+
Powered by **PaddleOCR** and smart field detection.
|
47 |
|
48 |
---
|
49 |
"""
|
|
|
54 |
uploader = gr.File(
|
55 |
label="📤 Upload Aadhaar / PAN Image(s)",
|
56 |
file_types=[".jpg", ".jpeg", ".png"],
|
57 |
+
file_count="multiple", # works on older Gradio; for newer, you can use gr.Files
|
58 |
)
|
59 |
submit_btn = gr.Button("🔍 Extract KYC Info", variant="primary")
|
60 |
|
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
# Change host/port if you need to expose it elsewhere
|
76 |
demo.launch()
|