HiTeckGroup commited on
Commit
5828293
·
verified ·
1 Parent(s): fb7bd89
Files changed (1) hide show
  1. app.py +0 -58
app.py DELETED
@@ -1,58 +0,0 @@
1
- from fastapi import FastAPI, Query
2
- import duckdb
3
-
4
- app = FastAPI(title="HiTeckGroup Telegram API")
5
-
6
- # Dataset path with 'data/' folder
7
- HF_FILE = "hf://datasets/HiTeckGroup/HiTeckGroup@main/data/*.parquet"
8
- con = duckdb.connect()
9
-
10
- @app.on_event("startup")
11
- def startup():
12
- con.execute("INSTALL httpfs;")
13
- con.execute("LOAD httpfs;")
14
-
15
- @app.get("/")
16
- def home():
17
- return {
18
- "status": "API active",
19
- "space": "HiTeckGroup/HiTeckGrouppp",
20
- "search_endpoint": "/search?user_id=...&username=..."
21
- }
22
-
23
- @app.get("/search")
24
- def search_user(
25
- user_id: str = Query(None, description="Search by User ID"),
26
- username: str = Query(None, description="Search by Username")
27
- ):
28
- try:
29
- query = """
30
- SELECT *
31
- FROM read_parquet(?)
32
- WHERE 1=1
33
- """
34
- params = [HF_FILE]
35
-
36
- if user_id:
37
- query += " AND CAST(user_id AS VARCHAR) = ?"
38
- params.append(user_id)
39
-
40
- if username:
41
- query += " AND CAST(username AS VARCHAR) ILIKE ?"
42
- params.append(f"%{username}%")
43
-
44
- query += " LIMIT 50"
45
-
46
- df = con.execute(query, params).fetchdf()
47
-
48
- if df.empty:
49
- return {"found": 0, "data": []}
50
-
51
- return {
52
- "found": len(df),
53
- "data": df.to_dict(orient="records")
54
- }
55
-
56
- except Exception as e:
57
- return {"error": str(e)}
58
-