Spaces:
Sleeping
Sleeping
Download app.py from CodeXDevloper/Simple: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/spaces/CodeXDevloper/Simple/resolve/eabe32b377df3ca4e6d43bca5a9d3618435746b6/app.py
- Command line
-
hf download hf://spaces/CodeXDevloper/Simple@eabe32b377df3ca4e6d43bca5a9d3618435746b6/app.py
-
curl -L -o app.py https://huggingface.co/spaces/CodeXDevloper/Simple/resolve/eabe32b377df3ca4e6d43bca5a9d3618435746b6/app.py
943 Bytes
| from fastapi import FastAPI, Query | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from datasets import load_dataset | |
| import os | |
| os.environ["HF_HOME"] = "/tmp/hf" | |
| app = FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| DATASET = "CodeXDevloper/MergedTgDataset" | |
| def root(): | |
| return {"status": "running", "usage": "/search?uid=385167100"} | |
| def search_uid(uid: str = Query(...)): | |
| try: | |
| ds = load_dataset(DATASET, split="train", streaming=True) | |
| scanned = 0 | |
| for row in ds: | |
| scanned += 1 | |
| if uid == str(row.get("user_id", "")).strip(): | |
| return {"found": True, "uid": uid, "data": row} | |
| if scanned >= 5000000: | |
| break | |
| return {"found": False, "uid": uid, "scanned": scanned} | |
| except Exception as e: | |
| return {"error": str(e)} |