SignLanguage-pro / request.py
thienphuc12339's picture
Update request.py
1a67d75 verified
import requests
# Thay <your-hf-space-url> bằng URL thực tế của bạn sau khi deploy lên Hugging Face Spaces
url = 'https://<your-hf-space-url>.hf.space/inference'
video_path = '/path/to/your_video.mp4' # Thay đổi đường dẫn tới video của bạn
# Các trường form data
data = {
'model_name': 'spoter', # Hoặc 'sl_gcn', 'dsta_slr' tùy vào mô hình bạn muốn sử dụng
'output_dir': 'custom_output_folder' # Thư mục để lưu kết quả, có thể tùy chỉnh
}
# Tệp video được tải lên
files = {
'file': open(video_path, 'rb')
}
try:
# Gửi request POST tới API
response = requests.post(url=url, data=data, files=files)
# Kiểm tra mã trạng thái HTTP
response.raise_for_status()
# In kết quả phản hồi dưới dạng JSON
print(response.json())
except requests.exceptions.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Ví dụ: 400, 500
except Exception as err:
print(f'Other error occurred: {err}') # Các lỗi khác