Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -25,5 +25,5 @@ Phone / identity lookup over India breach datasets. Zero local storage β DuckD
|
|
| 25 |
Rate limit: 30 requests/min per IP.
|
| 26 |
|
| 27 |
## Datasets used
|
| 28 |
-
- [
|
| 29 |
-
- [
|
|
|
|
| 25 |
Rate limit: 30 requests/min per IP.
|
| 26 |
|
| 27 |
## Datasets used
|
| 28 |
+
- [wannabeyour/truecallerdata](https://huggingface.co/datasets/wannabeyour/truecallerdata)
|
| 29 |
+
- [wannabeyour/icrm-hitek-fulldb](https://huggingface.co/datasets/wannabeyour/icrm-hitek-fulldb)
|
app.py
CHANGED
|
@@ -19,12 +19,14 @@ con.execute("INSTALL httpfs; LOAD httpfs;")
|
|
| 19 |
con.execute(f"CREATE SECRET hf_auth (TYPE HUGGINGFACE, TOKEN '{HF_TOKEN}');")
|
| 20 |
|
| 21 |
print("Mounting remote dataset views...")
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
con.execute("CREATE VIEW icmr_phone AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/icrm-hitek-fulldb/idx_phone.*.parquet')")
|
| 24 |
con.execute("CREATE VIEW icmr_aadhar AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/icrm-hitek-fulldb/idx_aadhar.*.parquet')")
|
| 25 |
|
| 26 |
# ββ IN-MEMORY QUERY CACHE ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 27 |
-
@lru_cache(maxsize=
|
| 28 |
def _raw(sql: str) -> tuple:
|
| 29 |
df = con.execute(sql).fetchdf()
|
| 30 |
return tuple(df.to_dict(orient="records"))
|
|
@@ -51,21 +53,27 @@ def _custom_init(self, *args, **kwargs):
|
|
| 51 |
def health():
|
| 52 |
return {"status": "online", "cache_size": _raw.cache_info().currsize}
|
| 53 |
|
| 54 |
-
# ---
|
| 55 |
@self.get("/api/truecaller")
|
| 56 |
@limiter.limit("30/minute")
|
| 57 |
def search_tc(request: fastapi.Request, mobile: str = ""):
|
| 58 |
clean = clean_digits(mobile, 10)
|
| 59 |
if len(clean) < 10:
|
| 60 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# --- ICMR Phone Endpoint ---
|
| 71 |
@self.get("/api/icmr/phone")
|
|
@@ -107,7 +115,8 @@ def _custom_init(self, *args, **kwargs):
|
|
| 107 |
if len(clean) < 10:
|
| 108 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 109 |
try:
|
| 110 |
-
|
|
|
|
| 111 |
icmr = cached_query(f"SELECT DISTINCT * FROM icmr_phone WHERE phoneNumber = '{clean}' LIMIT 15")
|
| 112 |
return {
|
| 113 |
"status": "success",
|
|
@@ -128,7 +137,8 @@ def gr_lookup(mobile: str):
|
|
| 128 |
if len(clean) < 10:
|
| 129 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 130 |
try:
|
| 131 |
-
|
|
|
|
| 132 |
icmr = cached_query(f"SELECT DISTINCT * FROM icmr_phone WHERE phoneNumber = '{clean}' LIMIT 15")
|
| 133 |
return {
|
| 134 |
"target": clean,
|
|
|
|
| 19 |
con.execute(f"CREATE SECRET hf_auth (TYPE HUGGINGFACE, TOKEN '{HF_TOKEN}');")
|
| 20 |
|
| 21 |
print("Mounting remote dataset views...")
|
| 22 |
+
# TrueCaller: fast curated subset is primary, full 223M dump is fallback
|
| 23 |
+
con.execute("CREATE VIEW tc_fast AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/truecallerdata/combined_selected_columns.parquet')")
|
| 24 |
+
con.execute("CREATE VIEW tc_full AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/truecallerdata/combined_truecaller_data.parquet')")
|
| 25 |
con.execute("CREATE VIEW icmr_phone AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/icrm-hitek-fulldb/idx_phone.*.parquet')")
|
| 26 |
con.execute("CREATE VIEW icmr_aadhar AS SELECT * FROM read_parquet('hf://datasets/wannabeyour/icrm-hitek-fulldb/idx_aadhar.*.parquet')")
|
| 27 |
|
| 28 |
# ββ IN-MEMORY QUERY CACHE ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 29 |
+
@lru_cache(maxsize=8192)
|
| 30 |
def _raw(sql: str) -> tuple:
|
| 31 |
df = con.execute(sql).fetchdf()
|
| 32 |
return tuple(df.to_dict(orient="records"))
|
|
|
|
| 53 |
def health():
|
| 54 |
return {"status": "online", "cache_size": _raw.cache_info().currsize}
|
| 55 |
|
| 56 |
+
# --- TrueCaller Endpoint (curated fast set, then full 223M fallback) ---
|
| 57 |
@self.get("/api/truecaller")
|
| 58 |
@limiter.limit("30/minute")
|
| 59 |
def search_tc(request: fastapi.Request, mobile: str = ""):
|
| 60 |
clean = clean_digits(mobile, 10)
|
| 61 |
if len(clean) < 10:
|
| 62 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 63 |
+
nums = f"('{clean}', '91{clean}')"
|
| 64 |
+
records = cached_query(f"SELECT DISTINCT Number, Name, Gender, Address, Email FROM tc_fast WHERE Number IN {nums} LIMIT 15")
|
| 65 |
+
if not records:
|
| 66 |
+
try:
|
| 67 |
+
big = cached_query(f"SELECT Number, Name, Email FROM tc_full WHERE Number IN {nums} LIMIT 15")
|
| 68 |
+
for b in big:
|
| 69 |
+
b.setdefault("source", "full_dump")
|
| 70 |
+
b.setdefault("Address", None); b.setdefault("Gender", None)
|
| 71 |
+
records = big or records
|
| 72 |
+
except Exception:
|
| 73 |
+
pass
|
| 74 |
+
if not records:
|
| 75 |
+
return {"status": "not_found", "message": f"No records found for target: {clean}", "count": 0, "data": []}
|
| 76 |
+
return {"status": "success", "count": len(records), "data": records}
|
| 77 |
|
| 78 |
# --- ICMR Phone Endpoint ---
|
| 79 |
@self.get("/api/icmr/phone")
|
|
|
|
| 115 |
if len(clean) < 10:
|
| 116 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 117 |
try:
|
| 118 |
+
nums = f"('{clean}', '91{clean}')"
|
| 119 |
+
tc = cached_query(f"SELECT DISTINCT Number, Name, Gender, Address, Email FROM tc_fast WHERE Number IN {nums} LIMIT 15")
|
| 120 |
icmr = cached_query(f"SELECT DISTINCT * FROM icmr_phone WHERE phoneNumber = '{clean}' LIMIT 15")
|
| 121 |
return {
|
| 122 |
"status": "success",
|
|
|
|
| 137 |
if len(clean) < 10:
|
| 138 |
return {"status": "error", "message": "Invalid input: 10-digit mobile number required"}
|
| 139 |
try:
|
| 140 |
+
nums = f"('{clean}', '91{clean}')"
|
| 141 |
+
tc = cached_query(f"SELECT DISTINCT Number, Name, Gender, Address, Email FROM tc_fast WHERE Number IN {nums} LIMIT 15")
|
| 142 |
icmr = cached_query(f"SELECT DISTINCT * FROM icmr_phone WHERE phoneNumber = '{clean}' LIMIT 15")
|
| 143 |
return {
|
| 144 |
"target": clean,
|