Download main.py from Rohit-kjp/rohit-api: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/Rohit-kjp/rohit-api/resolve/main/main.py
- Command line
-
hf download hf://spaces/Rohit-kjp/rohit-api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Rohit-kjp/rohit-api/resolve/main/main.py
1.26 kB
| from fastapi import FastAPI | |
| import duckdb | |
| app = FastAPI() | |
| DATASET_PATH = "hf://datasets/CutehackX/hitek-data-bucket/*.parquet" | |
| def home(): | |
| return {"message": "API is running! URL ke aage /search/MOBILE_NUMBER lagayein."} | |
| def search_data(mobile_number: str): | |
| query = f"SELECT * FROM '{DATASET_PATH}' WHERE mobile = '{mobile_number}' LIMIT 1" | |
| try: | |
| result = duckdb.query(query).to_df().to_dict(orient="records") | |
| if result: | |
| data = result[0] | |
| return { | |
| "status": "success", | |
| "result": { | |
| "Mobile Number": data.get("mobile", "N/A"), | |
| "Full Name": data.get("name", "N/A"), | |
| "Father Name": data.get("fname", "N/A"), | |
| "Address": data.get("address", "N/A"), | |
| "Circle/State": data.get("circle", "N/A"), | |
| "Alt Number": data.get("alt", "N/A"), | |
| "Email": data.get("email", "N/A") | |
| } | |
| } | |
| else: | |
| return {"status": "not found", "message": "Ye number database me nahi mila"} | |
| except Exception as e: | |
| return {"status": "error", "message": str(e)} | |