gopichandra commited on
Commit
fa803dc
·
verified ·
1 Parent(s): c70099c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -1,30 +1,17 @@
1
  import gradio as gr
2
- import pytesseract
3
- from PIL import Image
4
- import json
5
 
6
- def extract_fields(image):
7
- try:
8
- raw_text = pytesseract.image_to_string(image)
9
- lines = raw_text.split('\n')
10
- result = {}
11
 
12
- for line in lines:
13
- line = line.strip()
14
- if ':' in line:
15
- key, value = line.split(':', 1)
16
- result[key.strip()] = value.strip()
17
- elif len(line.split()) >= 2:
18
- result["line_" + str(len(result))] = line
19
 
20
- return json.dumps(result, indent=2)
21
- except Exception as e:
22
- return {"error": str(e)}
23
-
24
- gr.Interface(
25
- fn=extract_fields,
26
- inputs=gr.Image(type="pil"),
27
- outputs="json",
28
- title="Smart KYC OCR (Tesseract)",
29
- description="Upload Aadhaar or PAN image to extract key-value KYC fields using Tesseract OCR."
30
- ).launch()
 
1
  import gradio as gr
2
+ from utils import extract_kyc_fields
 
 
3
 
4
+ def process_document(file):
5
+ result = extract_kyc_fields(file.read())
6
+ return result
 
 
7
 
8
+ iface = gr.Interface(
9
+ fn=process_document,
10
+ inputs=gr.File(label="Upload Aadhaar/PAN image", type="binary"),
11
+ outputs=gr.JSON(label="Extracted KYC Fields"),
12
+ title="Smart KYC OCR",
13
+ description="Upload an Aadhaar or PAN card image to extract structured KYC fields using Tesseract OCR"
14
+ )
15
 
16
+ if __name__ == "__main__":
17
+ iface.launch()