File size: 857 Bytes
64e173b
 
 
 
 
 
 
03434f5
 
 
64e173b
 
 
 
 
 
 
 
 
 
 
03434f5
 
 
 
64e173b
 
 
 
 
03434f5
 
 
 
 
 
64e173b
 
03434f5
64e173b
 
 
 
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
from fastapi import FastAPI
import duckdb

app = FastAPI()

HF_PATH = "hf://datasets/tfqdeadlo/Inddata"

# HF parquet read support
duckdb.sql("INSTALL httpfs; LOAD httpfs;")

@app.get("/")
def home():
    return {"status": "API running"}

@app.get("/search")
def search(mobile: str):
    try:
        prefix = mobile[:3]

        query = f"""
        SELECT *
        FROM read_parquet(
            '{HF_PATH}/{prefix}/*.parquet',
            union_by_name=True
        )
        WHERE mobile = '{mobile}'
        """

        df = duckdb.query(query).to_df()

        if df.empty:
            return {
                "found": 0,
                "data": []
            }

        return {
            "found": len(df),
            "data": df.to_dict(orient="records")   # 🔥 FULL ROW
        }

    except Exception as e:
        return {"error": str(e)}