tamdang1350 commited on
Commit
5fd7825
·
verified ·
1 Parent(s): e4475ed

Create call.py

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