Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,22 +9,17 @@ con = duckdb.connect()
|
|
| 9 |
@asynccontextmanager
|
| 10 |
async def lifespan(app: FastAPI):
|
| 11 |
print("DuckDB extensions load ho rahi hain aur View ban raha hai...")
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
except Exception as e:
|
| 22 |
-
print(f"❌ Startup Initialization me error aaya: {e}")
|
| 23 |
yield
|
| 24 |
-
|
| 25 |
-
con.close()
|
| 26 |
-
except Exception:
|
| 27 |
-
pass
|
| 28 |
|
| 29 |
app = FastAPI(title="Super Fast Search API", lifespan=lifespan)
|
| 30 |
|
|
@@ -35,7 +30,7 @@ def home():
|
|
| 35 |
@app.get("/search")
|
| 36 |
async def search_mobile(mobile: str = Query(..., description="Enter mobile number to search")):
|
| 37 |
try:
|
| 38 |
-
#
|
| 39 |
query = """
|
| 40 |
SELECT mobile, name, fname, address, alt, circle, id, email
|
| 41 |
FROM users_view
|
|
@@ -61,7 +56,5 @@ async def search_mobile(mobile: str = Query(..., description="Enter mobile numbe
|
|
| 61 |
}
|
| 62 |
|
| 63 |
except Exception as e:
|
| 64 |
-
print(f"❌ Query execute karne me error: {e}")
|
| 65 |
# Internal error ko secure rakhne ke liye mask kiya hai
|
| 66 |
-
raise HTTPException(status_code=500, detail="Query timeout ya process nahi ho payi.")
|
| 67 |
-
|
|
|
|
| 9 |
@asynccontextmanager
|
| 10 |
async def lifespan(app: FastAPI):
|
| 11 |
print("DuckDB extensions load ho rahi hain aur View ban raha hai...")
|
| 12 |
+
con.execute("INSTALL httpfs; LOAD httpfs;")
|
| 13 |
+
|
| 14 |
+
# Parquet file ka correct URL
|
| 15 |
+
PARQUET_URL = "https://huggingface.co/datasets/tfqdeadlo/Inddatainonefile/resolve/main/users_data.parquet"
|
| 16 |
+
|
| 17 |
+
# Startup par hi Ek baar View bana kar metadata cache kar lete hain
|
| 18 |
+
# Isse har API request par network par load nahi padega
|
| 19 |
+
con.execute(f"CREATE OR REPLACE VIEW users_view AS SELECT * FROM read_parquet('{PARQUET_URL}')")
|
| 20 |
+
print("View taiyar hai! API requests ke liye taiyar hai.")
|
|
|
|
|
|
|
| 21 |
yield
|
| 22 |
+
con.close()
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
app = FastAPI(title="Super Fast Search API", lifespan=lifespan)
|
| 25 |
|
|
|
|
| 30 |
@app.get("/search")
|
| 31 |
async def search_mobile(mobile: str = Query(..., description="Enter mobile number to search")):
|
| 32 |
try:
|
| 33 |
+
# Ab hum direct cache kiye hue 'users_view' se data nikalenge
|
| 34 |
query = """
|
| 35 |
SELECT mobile, name, fname, address, alt, circle, id, email
|
| 36 |
FROM users_view
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
except Exception as e:
|
|
|
|
| 59 |
# Internal error ko secure rakhne ke liye mask kiya hai
|
| 60 |
+
raise HTTPException(status_code=500, detail="Query timeout ya process nahi ho payi.")
|
|
|