Spaces:
Sleeping
Sleeping
File size: 1,260 Bytes
5fd7825 eabb6d8 5fd7825 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import requests
import json
import sys
import os
BASE_URL = "https://tamdang1350-test.hf.space"
def process_file(filepath: str):
if not os.path.exists(filepath):
print(f"❌ Không tìm thấy file: {filepath}")
sys.exit(1)
ext = filepath.rsplit(".", 1)[-1].lower()
endpoint_map = {
"csv": "/process/csv",
"json": "/process/json",
"txt": "/process/text",
}
endpoint = endpoint_map.get(ext)
if not endpoint:
print(f"❌ Không hỗ trợ định dạng .{ext}. Hỗ trợ: csv, json, txt")
sys.exit(1)
print(f"📤 Đang gửi: {filepath} → {BASE_URL}{endpoint}")
with open(filepath, "rb") as f:
response = requests.post(
f"{BASE_URL}{endpoint}",
files={"file": (os.path.basename(filepath), f)}
)
if response.status_code == 200:
print("✅ Kết quả:")
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
else:
print(f"❌ Lỗi {response.status_code}: {response.text}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python call.py <file_path>")
print("Ví dụ: python call.py data.csv")
sys.exit(1)
process_file(sys.argv[1]) |