File size: 943 Bytes
eabe32b
 
 
 
2874220
eabe32b
2874220
eabe32b
2874220
eabe32b
 
 
 
 
 
2874220
eabe32b
2874220
eabe32b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Query
from fastapi.middleware.cors import CORSMiddleware
from datasets import load_dataset
import os

os.environ["HF_HOME"] = "/tmp/hf"

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

DATASET = "CodeXDevloper/MergedTgDataset"

@app.get("/")
def root():
    return {"status": "running", "usage": "/search?uid=385167100"}

@app.get("/search")
def search_uid(uid: str = Query(...)):
    try:
        ds = load_dataset(DATASET, split="train", streaming=True)
        scanned = 0
        for row in ds:
            scanned += 1
            if uid == str(row.get("user_id", "")).strip():
                return {"found": True, "uid": uid, "data": row}
            if scanned >= 5000000:
                break
        return {"found": False, "uid": uid, "scanned": scanned}
    except Exception as e:
        return {"error": str(e)}