Create danh_sach_pdf.py
Browse files- routes/danh_sach_pdf.py +18 -0
routes/danh_sach_pdf.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from huggingface_hub import list_repo_files
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
@router.get("/danh_sach_pdf")
|
| 8 |
+
async def danh_sach_pdf():
|
| 9 |
+
try:
|
| 10 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 11 |
+
repo_id = "doluong6/Quatest1"
|
| 12 |
+
|
| 13 |
+
all_files = list_repo_files(repo_id=repo_id, repo_type="dataset", token=HF_TOKEN)
|
| 14 |
+
pdfs = [f.split("/")[-1] for f in all_files if f.startswith("Tai_lieu/") and f.endswith(".pdf")]
|
| 15 |
+
|
| 16 |
+
return {"pdfs": pdfs}
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return {"pdfs": [], "error": str(e)}
|