Spaces:
Sleeping
Sleeping
okara chidera
commited on
force upgrade to gradio 4.44.1
Browse files- app.py +1 -12
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,9 +4,7 @@ from PIL import Image
|
|
| 4 |
import pytesseract
|
| 5 |
import re
|
| 6 |
|
| 7 |
-
|
| 8 |
def extract_text(file):
|
| 9 |
-
"""Extract text from PDF or image."""
|
| 10 |
if not file:
|
| 11 |
return ""
|
| 12 |
if file.name.endswith(".pdf"):
|
|
@@ -19,9 +17,7 @@ def extract_text(file):
|
|
| 19 |
img = Image.open(file.name)
|
| 20 |
return pytesseract.image_to_string(img)
|
| 21 |
|
| 22 |
-
|
| 23 |
def analyze_kyc(name, id_doc, selfie_doc, address_doc):
|
| 24 |
-
"""Extract and summarize key info from KYC documents."""
|
| 25 |
all_text = "\n".join([
|
| 26 |
extract_text(f) for f in [id_doc, selfie_doc, address_doc] if f
|
| 27 |
])
|
|
@@ -32,16 +28,13 @@ def analyze_kyc(name, id_doc, selfie_doc, address_doc):
|
|
| 32 |
"Detected IDs": ", ".join(re.findall(r"\b[A-Z]{1,3}\d{6,10}\b", all_text)) or "N/A",
|
| 33 |
"Possible DOBs": ", ".join(re.findall(r"\b\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}\b", all_text)) or "N/A",
|
| 34 |
}
|
| 35 |
-
|
| 36 |
summary = "\n".join([f"**{k}:** {v}" for k, v in findings.items()])
|
| 37 |
return summary, all_text[:1000]
|
| 38 |
|
| 39 |
-
|
| 40 |
demo = gr.Blocks(title="CreditCopilot — KYC Manager")
|
| 41 |
|
| 42 |
with demo:
|
| 43 |
gr.Markdown("## 🧠 CreditCopilot — KYC Manager\nExtract and summarize KYC documents for quick review.")
|
| 44 |
-
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column(scale=1):
|
| 47 |
name = gr.Textbox(label="Applicant Name", placeholder="Enter full name")
|
|
@@ -49,14 +42,10 @@ with demo:
|
|
| 49 |
selfie_doc = gr.File(label="Selfie / Liveness")
|
| 50 |
address_doc = gr.File(label="Proof of Address")
|
| 51 |
run_btn = gr.Button("Analyze Documents", variant="primary")
|
| 52 |
-
|
| 53 |
with gr.Column(scale=2):
|
| 54 |
summary = gr.Markdown()
|
| 55 |
text_preview = gr.Textbox(label="Extracted Text (Preview)", lines=15)
|
| 56 |
-
|
| 57 |
run_btn.click(analyze_kyc, [name, id_doc, selfie_doc, address_doc], [summary, text_preview])
|
| 58 |
|
| 59 |
-
|
| 60 |
if __name__ == "__main__":
|
| 61 |
-
|
| 62 |
-
demo.launch(share=True)
|
|
|
|
| 4 |
import pytesseract
|
| 5 |
import re
|
| 6 |
|
|
|
|
| 7 |
def extract_text(file):
|
|
|
|
| 8 |
if not file:
|
| 9 |
return ""
|
| 10 |
if file.name.endswith(".pdf"):
|
|
|
|
| 17 |
img = Image.open(file.name)
|
| 18 |
return pytesseract.image_to_string(img)
|
| 19 |
|
|
|
|
| 20 |
def analyze_kyc(name, id_doc, selfie_doc, address_doc):
|
|
|
|
| 21 |
all_text = "\n".join([
|
| 22 |
extract_text(f) for f in [id_doc, selfie_doc, address_doc] if f
|
| 23 |
])
|
|
|
|
| 28 |
"Detected IDs": ", ".join(re.findall(r"\b[A-Z]{1,3}\d{6,10}\b", all_text)) or "N/A",
|
| 29 |
"Possible DOBs": ", ".join(re.findall(r"\b\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}\b", all_text)) or "N/A",
|
| 30 |
}
|
|
|
|
| 31 |
summary = "\n".join([f"**{k}:** {v}" for k, v in findings.items()])
|
| 32 |
return summary, all_text[:1000]
|
| 33 |
|
|
|
|
| 34 |
demo = gr.Blocks(title="CreditCopilot — KYC Manager")
|
| 35 |
|
| 36 |
with demo:
|
| 37 |
gr.Markdown("## 🧠 CreditCopilot — KYC Manager\nExtract and summarize KYC documents for quick review.")
|
|
|
|
| 38 |
with gr.Row():
|
| 39 |
with gr.Column(scale=1):
|
| 40 |
name = gr.Textbox(label="Applicant Name", placeholder="Enter full name")
|
|
|
|
| 42 |
selfie_doc = gr.File(label="Selfie / Liveness")
|
| 43 |
address_doc = gr.File(label="Proof of Address")
|
| 44 |
run_btn = gr.Button("Analyze Documents", variant="primary")
|
|
|
|
| 45 |
with gr.Column(scale=2):
|
| 46 |
summary = gr.Markdown()
|
| 47 |
text_preview = gr.Textbox(label="Extracted Text (Preview)", lines=15)
|
|
|
|
| 48 |
run_btn.click(analyze_kyc, [name, id_doc, selfie_doc, address_doc], [summary, text_preview])
|
| 49 |
|
|
|
|
| 50 |
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|
|
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
pdfplumber
|
| 3 |
pytesseract
|
| 4 |
Pillow
|
|
|
|
| 1 |
+
# requirements.txt
|
| 2 |
+
gradio==4.44.1
|
| 3 |
pdfplumber
|
| 4 |
pytesseract
|
| 5 |
Pillow
|