Spaces:
Runtime error
Runtime error
Delete app.py
#2
by Kzzr0x - opened
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455from fastapi import FastAPI, HTTPException, Queryimport duckdbfrom contextlib import asynccontextmanager
app = FastAPI()
@asynccontextmanagerasync def lifespan(app: FastAPI): print("🟢 Space ready.") yield
@app.get("/")def home(): return {"message": "API Live! Use /search?phone=9860319038 OR /search?aadhar=912712797710 OR /search?q=9860319038"}
@app.get("/search")async def search_data( phone: str = Query(None, description="Search by Phone Number"), aadhar: str = Query(None, description="Search by Aadhar Number"), q: str = Query(None, description="Search by either Phone or Aadhar (generic)")): # Agar koi bhi parameter nahi diya toh error if not phone and not aadhar and not q: raise HTTPException(status_code=400, detail="Provide phone, aadhar, or q parameter") # Priority: q > phone > aadhar search_term = q or phone or aadhar
con = duckdb.connect() try: con.execute("PRAGMA memory_limit='800MB'") con.execute("PRAGMA threads=2") con.execute("INSTALL httpfs; LOAD httpfs;") PARQUET_URL = "https://huggingface.co/datasets/kzropx/icmr-parquet/resolve/main/icmr.parquet" # Dono columns (Phone aur Aadhar) mein search karo query = f""" SELECT name, fathersName, phoneNumber, aadharNumber, address, district, pincode, state, town FROM read_parquet('{PARQUET_URL}') WHERE phoneNumber = ? OR aadharNumber = ? LIMIT 1 """ result = con.execute(query, [search_term, search_term]).fetchall() if not result: return {"status": "error", "message": f"'{search_term}' se koi data nahi mila."} columns = [desc[0] for desc in con.description] return {"status": "success", "data": dict(zip(columns, result[0]))} except Exception as e: raise HTTPException(status_code=500, detail=f"Query error: {str(e)}") finally: con.close()app.pyDeleted-55