Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,13 @@ HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
|
| 13 |
if not HF_TOKEN:
|
| 14 |
raise Exception("HF_TOKEN environment variable not set. Add it in Space secrets.")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
con.execute(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Parquet URL (without ?token)
|
| 20 |
PARQUET_URL = "https://huggingface.co/datasets/tfqdeadlo/Inddatainone/resolve/main/users_data.parquet"
|
|
@@ -26,8 +31,7 @@ def home():
|
|
| 26 |
@app.get("/search")
|
| 27 |
async def search_mobile(mobile: str = Query(..., description="Mobile number to search")):
|
| 28 |
try:
|
| 29 |
-
#
|
| 30 |
-
# Predicate pushdown: sirf matching rows fetch hongi
|
| 31 |
query = f"""
|
| 32 |
SELECT mobile, name, fname, address, alt, circle, id, email
|
| 33 |
FROM read_parquet('{PARQUET_URL}')
|
|
@@ -44,6 +48,6 @@ async def search_mobile(mobile: str = Query(..., description="Mobile number to s
|
|
| 44 |
return {"status": "success", "data": row_dict}
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
-
# Token
|
| 48 |
error_msg = str(e).replace(HF_TOKEN, "[HIDDEN]")
|
| 49 |
raise HTTPException(status_code=500, detail=f"Error: {error_msg}")
|
|
|
|
| 13 |
if not HF_TOKEN:
|
| 14 |
raise Exception("HF_TOKEN environment variable not set. Add it in Space secrets.")
|
| 15 |
|
| 16 |
+
# Create HTTP secret for authentication (bearer token)
|
| 17 |
+
con.execute(f"""
|
| 18 |
+
CREATE SECRET IF NOT EXISTS hf_token (
|
| 19 |
+
TYPE HTTP,
|
| 20 |
+
HEADER 'Authorization' 'Bearer {HF_TOKEN}'
|
| 21 |
+
);
|
| 22 |
+
""")
|
| 23 |
|
| 24 |
# Parquet URL (without ?token)
|
| 25 |
PARQUET_URL = "https://huggingface.co/datasets/tfqdeadlo/Inddatainone/resolve/main/users_data.parquet"
|
|
|
|
| 31 |
@app.get("/search")
|
| 32 |
async def search_mobile(mobile: str = Query(..., description="Mobile number to search")):
|
| 33 |
try:
|
| 34 |
+
# Remote parquet direct read - no download, only required rows fetched
|
|
|
|
| 35 |
query = f"""
|
| 36 |
SELECT mobile, name, fname, address, alt, circle, id, email
|
| 37 |
FROM read_parquet('{PARQUET_URL}')
|
|
|
|
| 48 |
return {"status": "success", "data": row_dict}
|
| 49 |
|
| 50 |
except Exception as e:
|
| 51 |
+
# Token leak se bachao
|
| 52 |
error_msg = str(e).replace(HF_TOKEN, "[HIDDEN]")
|
| 53 |
raise HTTPException(status_code=500, detail=f"Error: {error_msg}")
|