Spaces:
Sleeping
Sleeping
Download call.py from tamdang1350/test: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/tamdang1350/test/resolve/main/call.py
- Command line
-
hf download hf://spaces/tamdang1350/test/call.py
-
curl -L -o call.py https://huggingface.co/spaces/tamdang1350/test/resolve/main/call.py
1.26 kB
| 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]) |