thienphuc12339 commited on
Commit
1a67d75
·
verified ·
1 Parent(s): 4d27720

Update request.py

Browse files
Files changed (1) hide show
  1. request.py +24 -8
request.py CHANGED
@@ -1,15 +1,31 @@
1
  import requests
2
 
3
- url = 'https://<your-hf-space-url>.hf.space/inference' # URL thực tế sau khi deploy lên HF
4
- video_path = '/path/to/your_video.mp4'
5
- params = {
6
- 'model_name': 'spoter',
7
- 'output_option': 'all',
8
- 'output_dir': 'custom_output_folder' # người dùng có thể chọn folder output
 
 
9
  }
 
 
10
  files = {
11
  'file': open(video_path, 'rb')
12
  }
13
 
14
- response = requests.post(url=url, files=files, params=params)
15
- print(response.json())
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
 
3
+ # Thay <your-hf-space-url> bằng URL thực tế của bạn sau khi deploy lên Hugging Face Spaces
4
+ url = 'https://<your-hf-space-url>.hf.space/inference'
5
+ video_path = '/path/to/your_video.mp4' # Thay đổi đường dẫn tới video của bạn
6
+
7
+ # Các trường form data
8
+ data = {
9
+ 'model_name': 'spoter', # Hoặc 'sl_gcn', 'dsta_slr' tùy vào mô hình bạn muốn sử dụng
10
+ 'output_dir': 'custom_output_folder' # Thư mục để lưu kết quả, có thể tùy chỉnh
11
  }
12
+
13
+ # Tệp video được tải lên
14
  files = {
15
  'file': open(video_path, 'rb')
16
  }
17
 
18
+ try:
19
+ # Gửi request POST tới API
20
+ response = requests.post(url=url, data=data, files=files)
21
+
22
+ # Kiểm tra mã trạng thái HTTP
23
+ response.raise_for_status()
24
+
25
+ # In kết quả phản hồi dưới dạng JSON
26
+ print(response.json())
27
+
28
+ except requests.exceptions.HTTPError as http_err:
29
+ print(f'HTTP error occurred: {http_err}') # Ví dụ: 400, 500
30
+ except Exception as err:
31
+ print(f'Other error occurred: {err}') # Các lỗi khác