tfqdeadlo commited on
Commit
0ae2729
·
verified ·
1 Parent(s): ed67e42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
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
- # Set HTTP headers for all outgoing httpfs requests
17
- con.execute(f"SET http_headers = 'Authorization: Bearer {HF_TOKEN}'")
 
 
 
 
 
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
- # DuckDB will read remote parquet directly (no download)
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 hide karo error se
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}")