Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ app = FastAPI()
|
|
| 5 |
|
| 6 |
HF_PATH = "hf://datasets/tfqdeadlo/Inddata"
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
@app.get("/")
|
| 9 |
def home():
|
| 10 |
return {"status": "API running"}
|
|
@@ -16,16 +19,24 @@ def search(mobile: str):
|
|
| 16 |
|
| 17 |
query = f"""
|
| 18 |
SELECT *
|
| 19 |
-
FROM read_parquet(
|
|
|
|
|
|
|
|
|
|
| 20 |
WHERE mobile = '{mobile}'
|
| 21 |
-
LIMIT 10
|
| 22 |
"""
|
| 23 |
|
| 24 |
df = duckdb.query(query).to_df()
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return {
|
| 27 |
"found": len(df),
|
| 28 |
-
"data": df.to_dict(orient="records")
|
| 29 |
}
|
| 30 |
|
| 31 |
except Exception as e:
|
|
|
|
| 5 |
|
| 6 |
HF_PATH = "hf://datasets/tfqdeadlo/Inddata"
|
| 7 |
|
| 8 |
+
# HF parquet read support
|
| 9 |
+
duckdb.sql("INSTALL httpfs; LOAD httpfs;")
|
| 10 |
+
|
| 11 |
@app.get("/")
|
| 12 |
def home():
|
| 13 |
return {"status": "API running"}
|
|
|
|
| 19 |
|
| 20 |
query = f"""
|
| 21 |
SELECT *
|
| 22 |
+
FROM read_parquet(
|
| 23 |
+
'{HF_PATH}/{prefix}/*.parquet',
|
| 24 |
+
union_by_name=True
|
| 25 |
+
)
|
| 26 |
WHERE mobile = '{mobile}'
|
|
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
df = duckdb.query(query).to_df()
|
| 30 |
|
| 31 |
+
if df.empty:
|
| 32 |
+
return {
|
| 33 |
+
"found": 0,
|
| 34 |
+
"data": []
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
return {
|
| 38 |
"found": len(df),
|
| 39 |
+
"data": df.to_dict(orient="records") # 🔥 FULL ROW
|
| 40 |
}
|
| 41 |
|
| 42 |
except Exception as e:
|