Spaces:
No application file
No application file
File size: 2,181 Bytes
af8c0c9 ad66f84 af8c0c9 ad66f84 af8c0c9 ad66f84 af8c0c9 ad66f84 af8c0c9 ad66f84 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | from fastapi import FastAPI, Query
from fastapi.middleware.cors import CORSMiddleware
from datasets import load_dataset
import os
app = FastAPI(title="Telegram UID Search API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
# Cache directory (Docker mein writable jagah)
os.environ["HF_HOME"] = "/tmp/hf"
os.environ["HF_DATASETS_CACHE"] = "/tmp/hf/datasets"
DATASET = "CodeXDevloper/MergedTgDataset"
@app.get("/")
def root():
return {
"status": "running",
"dataset": DATASET,
"usage": "/search?uid=385167100"
}
@app.get("/search")
def search_uid(uid: str = Query(..., description="Telegram UID")):
"""Poore dataset mein UID dhoondho"""
try:
ds = load_dataset(DATASET, split="train", streaming=True)
scanned = 0
max_scan = 5000000 # 50 lakh rows tak
for row in ds:
scanned += 1
# user_id match karo
if uid == str(row.get("user_id", "")).strip():
return {
"found": True,
"uid": uid,
"scanned": scanned,
"data": {
"user_id": row.get("user_id"),
"username": row.get("username"),
"first_name": row.get("first_name"),
"last_name": row.get("last_name"),
"phone": row.get("phone"),
"email": row.get("email"),
"status": row.get("status"),
"linked_id": row.get("linked_id"),
"linked_name": row.get("linked_name"),
"linked_handle": row.get("linked_handle"),
}
}
if scanned >= max_scan:
break
return {
"found": False,
"uid": uid,
"scanned": scanned,
"message": f"UID '{uid}' nahi mila ({scanned} rows scan kiye)"
}
except Exception as e:
return {"error": str(e), "uid": uid} |