Spaces:
Running
Running
Delete app.py with huggingface_hub
Browse files
app.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI, Header, HTTPException
|
| 2 |
-
import sqlite3
|
| 3 |
-
|
| 4 |
-
app = FastAPI()
|
| 5 |
-
API_KEY = "g786"
|
| 6 |
-
|
| 7 |
-
@app.get("/")
|
| 8 |
-
def home():
|
| 9 |
-
return {"message": "API is Running!", "Search_Endpoint": "/search?word=NAME_OR_NUMBER"}
|
| 10 |
-
|
| 11 |
-
@app.get("/search")
|
| 12 |
-
def search(word: str, x_api_key: str = Header(None)):
|
| 13 |
-
if x_api_key != API_KEY:
|
| 14 |
-
raise HTTPException(status_code=403, detail="Invalid API Key!")
|
| 15 |
-
|
| 16 |
-
conn = sqlite3.connect('CarOwners_Full_Final.db')
|
| 17 |
-
conn.row_factory = sqlite3.Row
|
| 18 |
-
cursor = conn.cursor()
|
| 19 |
-
|
| 20 |
-
val = f"%{word}%"
|
| 21 |
-
sql = "SELECT * FROM owners WHERE Name LIKE ? OR [Mobile No] LIKE ? OR City LIKE ? OR Model LIKE ? OR Address LIKE ? LIMIT 100"
|
| 22 |
-
|
| 23 |
-
cursor.execute(sql, (val, val, val, val, val))
|
| 24 |
-
results = [dict(row) for row in cursor.fetchall()]
|
| 25 |
-
conn.close()
|
| 26 |
-
|
| 27 |
-
return {"status": "success", "count": len(results), "data": results}
|
| 28 |
-
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
import uvicorn
|
| 31 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|