Spaces:
Sleeping
Sleeping
Download tests/test_request.py from Jay9115/Deep_fake_Model_load: direct link, hf CLI and curl.
- Browser
- Download file 648 Bytes
-
https://huggingface.co/spaces/Jay9115/Deep_fake_Model_load/resolve/main/tests/test_request.py
- Command line
-
hf download hf://spaces/Jay9115/Deep_fake_Model_load/tests/test_request.py
-
curl -L -o test_request.py https://huggingface.co/spaces/Jay9115/Deep_fake_Model_load/resolve/main/tests/test_request.py
648 Bytes
| import sys | |
| import os | |
| import json | |
| import requests | |
| def main(): | |
| img_path = sys.argv[1] if len(sys.argv) > 1 else 'test.jpg' | |
| url = 'http://127.0.0.1:5000/api/predict' | |
| if not os.path.exists(img_path): | |
| print(f"File not found: {img_path}") | |
| return | |
| try: | |
| with open(img_path, 'rb') as f: | |
| files = {'file': f} | |
| resp = requests.post(url, files=files) | |
| print(f'Status code: {resp.status_code}') | |
| try: | |
| print(json.dumps(resp.json(), indent=2)) | |
| except Exception: | |
| print(resp.text) | |
| except requests.exceptions.ConnectionError as e: | |
| print('Connection error: Is the Flask server running?') | |
| print(e) | |
| if __name__ == '__main__': | |
| main() | |