Watchhrr commited on
Commit
ccbf139
·
verified ·
1 Parent(s): 3536edd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -6,8 +6,6 @@ app = FastAPI()
6
 
7
  # --- 🔐 SECURITY ---
8
  VALID_KEYS = {"Satuu5": "Master_Admin"}
9
-
10
- # Hugging Face Settings se Secret uthayega
11
  HF_TOKEN = os.getenv("HF_TOKEN")
12
  DATA_URL = "https://huggingface.co/datasets/Watchhrr/HITECH_DB/resolve/main/Hi-Tek-DB.zip.001"
13
 
@@ -17,19 +15,17 @@ def home():
17
 
18
  @app.get("/search")
19
  def search(query: str, type: str = "phone", key: str = None):
20
- # 1. Key Check
21
  if key not in VALID_KEYS:
22
  raise HTTPException(status_code=403, detail="Invalid API Key!")
23
 
24
  con = duckdb.connect()
25
  try:
26
- # Authentication using Environment Variable
27
- con.execute(f"SET http_keep_alive=false;")
28
- con.execute(f"INSTALL httpfs; LOAD httpfs;")
29
  if HF_TOKEN:
30
- con.execute(f"SET http_header = 'Authorization: Bearer {HF_TOKEN}';")
31
 
32
- # Database Search
33
  sql = f"SELECT * FROM read_csv_auto('{DATA_URL}') WHERE {type} = ? LIMIT 5"
34
  result = con.execute(sql, [query]).df().to_dict(orient="records")
35
 
 
6
 
7
  # --- 🔐 SECURITY ---
8
  VALID_KEYS = {"Satuu5": "Master_Admin"}
 
 
9
  HF_TOKEN = os.getenv("HF_TOKEN")
10
  DATA_URL = "https://huggingface.co/datasets/Watchhrr/HITECH_DB/resolve/main/Hi-Tek-DB.zip.001"
11
 
 
15
 
16
  @app.get("/search")
17
  def search(query: str, type: str = "phone", key: str = None):
 
18
  if key not in VALID_KEYS:
19
  raise HTTPException(status_code=403, detail="Invalid API Key!")
20
 
21
  con = duckdb.connect()
22
  try:
23
+ con.execute("INSTALL httpfs; LOAD httpfs;")
24
+ # Fix: http_headers (not http_header)
 
25
  if HF_TOKEN:
26
+ con.execute(f"SET http_headers = 'Authorization: Bearer {HF_TOKEN}';")
27
 
28
+ # DuckDB handles the split zip automatically
29
  sql = f"SELECT * FROM read_csv_auto('{DATA_URL}') WHERE {type} = ? LIMIT 5"
30
  result = con.execute(sql, [query]).df().to_dict(orient="records")
31