Upload 5 files
Browse files- app.py +2 -4
- routes/__init__.py +0 -2
- routes/baogia_router.py +0 -1
- routes/doanhthu_router.py +0 -1
- routes/pyc_router.py +1 -4
app.py
CHANGED
|
@@ -1,19 +1,17 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
-
from routes import pyc_router, baogia_router, doanhthu_router
|
| 4 |
|
| 5 |
app = FastAPI(title="Backend Quản lý Phòng Thí Nghiệm")
|
| 6 |
|
| 7 |
-
# Cho phép frontend gọi API
|
| 8 |
app.add_middleware(
|
| 9 |
CORSMiddleware,
|
| 10 |
-
allow_origins=["https://doluong6--qlht6.hf.space"],
|
| 11 |
allow_credentials=True,
|
| 12 |
allow_methods=["*"],
|
| 13 |
allow_headers=["*"],
|
| 14 |
)
|
| 15 |
|
| 16 |
-
# Gắn các router với prefix tương ứng
|
| 17 |
app.include_router(pyc_router.router, prefix="/pyc")
|
| 18 |
app.include_router(baogia_router.router, prefix="/baogia")
|
| 19 |
app.include_router(doanhthu_router.router, prefix="/doanhthu")
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from routes import pyc_router, baogia_router, doanhthu_router
|
| 4 |
|
| 5 |
app = FastAPI(title="Backend Quản lý Phòng Thí Nghiệm")
|
| 6 |
|
|
|
|
| 7 |
app.add_middleware(
|
| 8 |
CORSMiddleware,
|
| 9 |
+
allow_origins=["https://doluong6--qlht6.hf.space"],
|
| 10 |
allow_credentials=True,
|
| 11 |
allow_methods=["*"],
|
| 12 |
allow_headers=["*"],
|
| 13 |
)
|
| 14 |
|
|
|
|
| 15 |
app.include_router(pyc_router.router, prefix="/pyc")
|
| 16 |
app.include_router(baogia_router.router, prefix="/baogia")
|
| 17 |
app.include_router(doanhthu_router.router, prefix="/doanhthu")
|
routes/__init__.py
CHANGED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
# Khởi tạo thư mục forms
|
| 2 |
-
|
|
|
|
|
|
|
|
|
routes/baogia_router.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# routes/baogia_router.py
|
| 2 |
from fastapi import APIRouter
|
| 3 |
|
| 4 |
router = APIRouter()
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
router = APIRouter()
|
routes/doanhthu_router.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# routes/doanhthu_router.py
|
| 2 |
from fastapi import APIRouter
|
| 3 |
|
| 4 |
router = APIRouter()
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
router = APIRouter()
|
routes/pyc_router.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# pyc_router.py
|
| 2 |
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
| 3 |
from huggingface_hub import upload_file
|
| 4 |
from openpyxl import load_workbook
|
|
@@ -16,7 +15,6 @@ async def upload_pyc(
|
|
| 16 |
):
|
| 17 |
if password != USER_PASSWORD:
|
| 18 |
raise HTTPException(status_code=403, detail="❌ Sai mật khẩu")
|
| 19 |
-
|
| 20 |
if not file.filename.endswith(".xlsx"):
|
| 21 |
raise HTTPException(status_code=400, detail="❌ Chỉ nhận file .xlsx")
|
| 22 |
|
|
@@ -29,7 +27,7 @@ async def upload_pyc(
|
|
| 29 |
ws = wb.active
|
| 30 |
ten_khach = str(ws["I8"].value or "Khach_hang_khong_ten").strip()
|
| 31 |
ma_phieu = str(ws["D3"].value).strip().replace("/", "-")
|
| 32 |
-
thang = f"{int(ws['BS3
|
| 33 |
nam = str(ws["BX3"].value)
|
| 34 |
thu_muc_khach = f"{ten_khach}_{nam}-{thang}_{ma_phieu}"
|
| 35 |
path_in_repo = f"Khach_hang/{thu_muc_khach}/Phieu_yeu_cau/{file.filename}"
|
|
@@ -41,7 +39,6 @@ async def upload_pyc(
|
|
| 41 |
repo_type="space",
|
| 42 |
token=HF_TOKEN
|
| 43 |
)
|
| 44 |
-
|
| 45 |
except Exception as e:
|
| 46 |
raise HTTPException(status_code=500, detail=f"Lỗi upload: {e}")
|
| 47 |
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
| 2 |
from huggingface_hub import upload_file
|
| 3 |
from openpyxl import load_workbook
|
|
|
|
| 15 |
):
|
| 16 |
if password != USER_PASSWORD:
|
| 17 |
raise HTTPException(status_code=403, detail="❌ Sai mật khẩu")
|
|
|
|
| 18 |
if not file.filename.endswith(".xlsx"):
|
| 19 |
raise HTTPException(status_code=400, detail="❌ Chỉ nhận file .xlsx")
|
| 20 |
|
|
|
|
| 27 |
ws = wb.active
|
| 28 |
ten_khach = str(ws["I8"].value or "Khach_hang_khong_ten").strip()
|
| 29 |
ma_phieu = str(ws["D3"].value).strip().replace("/", "-")
|
| 30 |
+
thang = f"{int(ws['BS3"].value):02}"
|
| 31 |
nam = str(ws["BX3"].value)
|
| 32 |
thu_muc_khach = f"{ten_khach}_{nam}-{thang}_{ma_phieu}"
|
| 33 |
path_in_repo = f"Khach_hang/{thu_muc_khach}/Phieu_yeu_cau/{file.filename}"
|
|
|
|
| 39 |
repo_type="space",
|
| 40 |
token=HF_TOKEN
|
| 41 |
)
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
raise HTTPException(status_code=500, detail=f"Lỗi upload: {e}")
|
| 44 |
|