Spaces:
Sleeping

doluong6 commited on
Commit
c47eaee
·
verified ·
1 Parent(s): d070f83

Create danh_sach_thu_muc_khach_hang.py

Browse files
routes/danh_sach_thu_muc_khach_hang.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+ from huggingface_hub import list_repo_files
3
+ import os
4
+
5
+ router = APIRouter()
6
+
7
+ @router.get("/thu_muc_khach_hang")
8
+ async def thu_muc_khach_hang():
9
+ try:
10
+ HF_TOKEN = os.environ.get("HF_TOKEN")
11
+ repo_id = "doluong6/Quatest1"
12
+ thu_muc_cha = "Khach_hang/"
13
+
14
+ all_files = list_repo_files(repo_id=repo_id, repo_type="dataset", token=HF_TOKEN)
15
+ cac_thu_muc = set()
16
+
17
+ for file in all_files:
18
+ if file.startswith(thu_muc_cha):
19
+ parts = file.split("/")
20
+ if len(parts) >= 2:
21
+ cac_thu_muc.add(parts[1]) # Lấy tên thư mục con
22
+
23
+ return sorted(list(cac_thu_muc))
24
+
25
+ except Exception as e:
26
+ return {"error": str(e)}