Spaces:
Sleeping
Sleeping
Pavan+2-at-244075126032
commited on
Commit
·
7d200f3
1
Parent(s):
1c8b1aa
Added uidai server
Browse files- app/__init__.py +6 -6
- app/api.py +22 -2
- app/routes/uidaiServices.py +65 -0
app/__init__.py
CHANGED
@@ -6,11 +6,11 @@ def create_app():
|
|
6 |
from .api import ocr_bp
|
7 |
app.register_blueprint(ocr_bp)
|
8 |
|
9 |
-
with app.app_context():
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
return app
|
|
|
6 |
from .api import ocr_bp
|
7 |
app.register_blueprint(ocr_bp)
|
8 |
|
9 |
+
# with app.app_context():
|
10 |
+
# # Load model once
|
11 |
+
# app.models = {
|
12 |
+
# 'adhaarModel': YOLO('models/aadhaarYolov8.pt'),
|
13 |
+
# 'panModel': YOLO('models/PanModel_v6.pt') # Load additional models as needed
|
14 |
+
# }
|
15 |
|
16 |
return app
|
app/api.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
-
from
|
|
|
|
|
2 |
import requests
|
3 |
import os
|
4 |
from .routes.adhaarApi import ocrAdhaar
|
5 |
from .routes.panApi import ocrPan
|
|
|
6 |
ocr_bp = Blueprint('ocr', __name__)
|
7 |
session = requests.Session()
|
8 |
mode = os.getenv("PROJECT_MODE")
|
@@ -13,4 +16,21 @@ def getResponse_Pan():
|
|
13 |
|
14 |
@ocr_bp.route('/ocrAdhaar', methods=['POST'])
|
15 |
def getResponse_Adhaar():
|
16 |
-
return ocrAdhaar(mode, session)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# from app.services.UidaiServices.uidaiServices import generate_captcha, validate_aadhaar
|
2 |
+
from app.routes.uidaiServices import generate_captcha, validate_aadhaar
|
3 |
+
from flask import Blueprint, request, jsonify
|
4 |
import requests
|
5 |
import os
|
6 |
from .routes.adhaarApi import ocrAdhaar
|
7 |
from .routes.panApi import ocrPan
|
8 |
+
import uuid
|
9 |
ocr_bp = Blueprint('ocr', __name__)
|
10 |
session = requests.Session()
|
11 |
mode = os.getenv("PROJECT_MODE")
|
|
|
16 |
|
17 |
@ocr_bp.route('/ocrAdhaar', methods=['POST'])
|
18 |
def getResponse_Adhaar():
|
19 |
+
return ocrAdhaar(mode, session)
|
20 |
+
|
21 |
+
# Route to generate captcha
|
22 |
+
@ocr_bp.route('/generateCaptcha', methods=['POST'])
|
23 |
+
def get_response_captcha():
|
24 |
+
# Generate a new UUID for transactionId
|
25 |
+
transaction_id = uuid.uuid4()
|
26 |
+
result = generate_captcha(transaction_id)
|
27 |
+
return jsonify(result)
|
28 |
+
|
29 |
+
# Route to validate Aadhaar data
|
30 |
+
@ocr_bp.route('/validateData', methods=['POST'])
|
31 |
+
def get_response_uidai():
|
32 |
+
data = request.json
|
33 |
+
if not data or 'transactionId' not in data:
|
34 |
+
return jsonify({"error": "transactionId is required in the request body"}), 400
|
35 |
+
result = validate_aadhaar(data)
|
36 |
+
return jsonify(result)
|
app/routes/uidaiServices.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
# Function to generate captcha
|
3 |
+
def generate_captcha(transaction_id):
|
4 |
+
url = "https://tathya.uidai.gov.in/audioCaptchaService/api/captcha/v3/generation"
|
5 |
+
headers = {
|
6 |
+
"Accept": "application/json, text/plain, */*",
|
7 |
+
"Accept-Language": "verifyAadhaar_IN",
|
8 |
+
"Connection": "keep-alive",
|
9 |
+
"Content-Type": "application/json",
|
10 |
+
"DNT": "1",
|
11 |
+
"Origin": "https://myaadhaar.uidai.gov.in",
|
12 |
+
"Referer": "https://myaadhaar.uidai.gov.in/",
|
13 |
+
"Sec-Fetch-Dest": "empty",
|
14 |
+
"Sec-Fetch-Mode": "cors",
|
15 |
+
"Sec-Fetch-Site": "same-site",
|
16 |
+
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36 Edg/125.0.0.0",
|
17 |
+
"appid": "MYAADHAAR",
|
18 |
+
"sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
19 |
+
"sec-ch-ua-mobile": "?1",
|
20 |
+
"sec-ch-ua-platform": '"Android"',
|
21 |
+
"x-request-id": str(transaction_id), # Using the UUID
|
22 |
+
}
|
23 |
+
data = {
|
24 |
+
"captchaLength": "6",
|
25 |
+
"captchaType": "1",
|
26 |
+
"audioCaptchaRequired": False
|
27 |
+
}
|
28 |
+
|
29 |
+
try:
|
30 |
+
response = requests.post(url, headers=headers, json=data)
|
31 |
+
response.raise_for_status() # Raise HTTPError for bad responses
|
32 |
+
return response.json()
|
33 |
+
except requests.RequestException as e:
|
34 |
+
print(f"Error in Captcha Generation from UIDAI: {e}")
|
35 |
+
return {"error": str(e)}
|
36 |
+
|
37 |
+
# Function to validate Aadhaar
|
38 |
+
def validate_aadhaar(data):
|
39 |
+
url = "https://tathya.uidai.gov.in/uidVerifyRetrieveService/api/verifyUID"
|
40 |
+
headers = {
|
41 |
+
"Accept": "application/json, text/plain, */*",
|
42 |
+
"Accept-Language": "en_IN",
|
43 |
+
"Connection": "keep-alive",
|
44 |
+
"Content-Type": "application/json",
|
45 |
+
"DNT": "1",
|
46 |
+
"Origin": "https://myaadhaar.uidai.gov.in",
|
47 |
+
"Referer": "https://myaadhaar.uidai.gov.in/",
|
48 |
+
"Sec-Fetch-Dest": "empty",
|
49 |
+
"Sec-Fetch-Mode": "cors",
|
50 |
+
"Sec-Fetch-Site": "same-site",
|
51 |
+
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36 Edg/125.0.0.0",
|
52 |
+
"appid": "MYAADHAAR",
|
53 |
+
"sec-ch-ua": '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
|
54 |
+
"sec-ch-ua-mobile": "?1",
|
55 |
+
"sec-ch-ua-platform": '"Android"',
|
56 |
+
"x-request-id": data.get("transactionId"),
|
57 |
+
}
|
58 |
+
|
59 |
+
try:
|
60 |
+
response = requests.post(url, headers=headers, json=data)
|
61 |
+
response.raise_for_status() # Raise HTTPError for bad responses
|
62 |
+
return response.json()
|
63 |
+
except requests.RequestException as e:
|
64 |
+
print(f"Error in Aadhaar Validation: {e}")
|
65 |
+
return {"status": response.status_code, "message": str(e)}
|