Update app.py
Browse files
app.py
CHANGED
|
@@ -649,31 +649,38 @@ async def danh_muc_thiet_bi():
|
|
| 649 |
|
| 650 |
except Exception as e:
|
| 651 |
raise HTTPException(status_code=500, detail=f"Lỗi đọc danh mục thiết bị: {str(e)}")
|
|
|
|
| 652 |
@app.post("/cap_nhat_hoa_chat")
|
| 653 |
async def cap_nhat_hoa_chat(request: Request):
|
| 654 |
try:
|
| 655 |
-
|
| 656 |
-
columns =
|
| 657 |
-
|
| 658 |
|
| 659 |
-
|
|
|
|
| 660 |
|
| 661 |
-
|
| 662 |
-
df.
|
| 663 |
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
upload_file(
|
| 666 |
path_or_fileobj=temp_path,
|
| 667 |
path_in_repo="Quan_ly_hoa_chat.xlsx",
|
| 668 |
-
repo_id=
|
| 669 |
repo_type="dataset",
|
| 670 |
token=os.environ.get("HF_TOKEN")
|
| 671 |
)
|
| 672 |
|
| 673 |
-
return {"message": "✅ Đã cập nhật
|
| 674 |
|
| 675 |
except Exception as e:
|
| 676 |
-
|
| 677 |
@app.get("/quan_ly_hoa_chat")
|
| 678 |
async def quan_ly_hoa_chat():
|
| 679 |
try:
|
|
|
|
| 649 |
|
| 650 |
except Exception as e:
|
| 651 |
raise HTTPException(status_code=500, detail=f"Lỗi đọc danh mục thiết bị: {str(e)}")
|
| 652 |
+
|
| 653 |
@app.post("/cap_nhat_hoa_chat")
|
| 654 |
async def cap_nhat_hoa_chat(request: Request):
|
| 655 |
try:
|
| 656 |
+
data = await request.json()
|
| 657 |
+
columns = data.get("columns", [])
|
| 658 |
+
rows = data.get("data", [])
|
| 659 |
|
| 660 |
+
if not columns or not rows:
|
| 661 |
+
return JSONResponse(content={"message": "Không có dữ liệu để cập nhật!"}, status_code=400)
|
| 662 |
|
| 663 |
+
# ✅ Tạo DataFrame từ dữ liệu gửi về
|
| 664 |
+
df = pd.DataFrame(rows, columns=columns)
|
| 665 |
|
| 666 |
+
# ✅ Lưu vào file Excel tạm
|
| 667 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
|
| 668 |
+
temp_path = tmp.name
|
| 669 |
+
df.to_excel(temp_path, sheet_name="HOA CHAT SU DUNG", index=False)
|
| 670 |
+
|
| 671 |
+
# ✅ Ghi đè lên Hugging Face Dataset
|
| 672 |
upload_file(
|
| 673 |
path_or_fileobj=temp_path,
|
| 674 |
path_in_repo="Quan_ly_hoa_chat.xlsx",
|
| 675 |
+
repo_id="doluong6/Quatest1",
|
| 676 |
repo_type="dataset",
|
| 677 |
token=os.environ.get("HF_TOKEN")
|
| 678 |
)
|
| 679 |
|
| 680 |
+
return JSONResponse(content={"message": "✅ Đã cập nhật thành công vào Dataset!"})
|
| 681 |
|
| 682 |
except Exception as e:
|
| 683 |
+
return JSONResponse(content={"message": f"❌ Lỗi: {str(e)}"}, status_code=500)
|
| 684 |
@app.get("/quan_ly_hoa_chat")
|
| 685 |
async def quan_ly_hoa_chat():
|
| 686 |
try:
|