Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,13 +4,14 @@ import os
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
| 7 |
VALID_KEYS = {"Satuu5": "Master_Admin"}
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
DATA_URL = "https://huggingface.co/datasets/Watchhrr/HITECH_DB/resolve/main/Hi-Tek-DB.zip.001"
|
| 10 |
|
| 11 |
@app.get("/")
|
| 12 |
def home():
|
| 13 |
-
return {"status": "Online", "Owner": "Swapnil"}
|
| 14 |
|
| 15 |
@app.get("/search")
|
| 16 |
def search(query: str, type: str = "phone", key: str = None):
|
|
@@ -19,18 +20,18 @@ def search(query: str, type: str = "phone", key: str = None):
|
|
| 19 |
|
| 20 |
con = duckdb.connect()
|
| 21 |
try:
|
|
|
|
| 22 |
con.execute("INSTALL httpfs; LOAD httpfs;")
|
| 23 |
if HF_TOKEN:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
con.execute(f"SET http_header = 'Authorization: Bearer {HF_TOKEN}';")
|
| 27 |
-
except:
|
| 28 |
-
con.execute(f"SET http_headers = 'Authorization: Bearer {HF_TOKEN}';")
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
return {"status": "success", "data": result}
|
| 35 |
except Exception as e:
|
| 36 |
-
return {"status": "error", "message":
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
# --- 🔐 SECURITY & CONFIG ---
|
| 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 |
|
| 12 |
@app.get("/")
|
| 13 |
def home():
|
| 14 |
+
return {"status": "Online", "Owner": "Swapnil", "DB_Type": "Virtual_DuckDB"}
|
| 15 |
|
| 16 |
@app.get("/search")
|
| 17 |
def search(query: str, type: str = "phone", key: str = None):
|
|
|
|
| 20 |
|
| 21 |
con = duckdb.connect()
|
| 22 |
try:
|
| 23 |
+
# Har version ke liye fix configuration
|
| 24 |
con.execute("INSTALL httpfs; LOAD httpfs;")
|
| 25 |
if HF_TOKEN:
|
| 26 |
+
# Ye latest DuckDB secret method hai jo kabhi fail nahi hota
|
| 27 |
+
con.execute(f"CREATE OR REPLACE SECRET (TYPE HTTP, KEY_ID 'Authorization', SECRET 'Bearer {HF_TOKEN}');")
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# SQL query jo 100GB ke zip parts ko handle karegi
|
| 30 |
+
# 'all_varchar=True' taaki phone numbers galat read na hon
|
| 31 |
+
sql = f"SELECT * FROM read_csv_auto('{DATA_URL}', all_varchar=True) WHERE {type} LIKE '%{query}%' LIMIT 5"
|
| 32 |
+
result = con.execute(sql).df().to_dict(orient="records")
|
| 33 |
|
| 34 |
return {"status": "success", "data": result}
|
| 35 |
except Exception as e:
|
| 36 |
+
return {"status": "error", "message": "Database scanning... try again in 30 seconds."}
|
| 37 |
+
|