Delete app.py
Browse files
app.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
-
from contextlib import asynccontextmanager
|
| 3 |
-
import duckdb
|
| 4 |
-
|
| 5 |
-
HF_FILE = "hf://datasets/warmifans/Inddatainonefile@main/users_data.parquet"
|
| 6 |
-
|
| 7 |
-
@asynccontextmanager
|
| 8 |
-
async def lifespan(app: FastAPI):
|
| 9 |
-
con = duckdb.connect()
|
| 10 |
-
con.execute("INSTALL httpfs;")
|
| 11 |
-
con.execute("LOAD httpfs;")
|
| 12 |
-
con.execute(f"CREATE VIEW users AS SELECT * FROM read_parquet('{HF_FILE}');")
|
| 13 |
-
|
| 14 |
-
app.state.db = con
|
| 15 |
-
yield
|
| 16 |
-
|
| 17 |
-
con.close()
|
| 18 |
-
|
| 19 |
-
app = FastAPI(lifespan=lifespan)
|
| 20 |
-
|
| 21 |
-
@app.get("/")
|
| 22 |
-
def home():
|
| 23 |
-
return {"status": "API running"}
|
| 24 |
-
|
| 25 |
-
@app.get("/email")
|
| 26 |
-
def search(email: str = Query(..., min_length=1)):
|
| 27 |
-
try:
|
| 28 |
-
df = app.state.db.execute(
|
| 29 |
-
"SELECT * FROM users WHERE email = ?;",
|
| 30 |
-
[email]
|
| 31 |
-
).fetchdf()
|
| 32 |
-
|
| 33 |
-
if df.empty:
|
| 34 |
-
return {"found": 0, "data": []}
|
| 35 |
-
|
| 36 |
-
return {
|
| 37 |
-
"found": len(df),
|
| 38 |
-
"data": df.to_dict(orient="records")
|
| 39 |
-
|
| 40 |
-
import traceback
|
| 41 |
-
except Exception:
|
| 42 |
-
traceback.print_exc()
|
| 43 |
-
raise
|
| 44 |
-
|
| 45 |
-
except Exception as e:
|
| 46 |
-
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|