Download test_api.py from manny1313/my-ml-api: direct link, hf CLI and curl.
- Browser
- Download file 540 Bytes
-
https://huggingface.co/spaces/manny1313/my-ml-api/resolve/main/test_api.py
- Command line
-
hf download hf://spaces/manny1313/my-ml-api/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/manny1313/my-ml-api/resolve/main/test_api.py
540 Bytes
| import requests | |
| # Define the API URL (update with your actual deployment URL when hosted) | |
| API_URL = "http://127.0.0.1:8000/predict" # Localhost for testing | |
| # Example input data | |
| test_data = { | |
| "soil_moisture": 25.0, | |
| "N": 50.0, | |
| "P": 30.0, | |
| "K": 20.0, | |
| "soil_pH": 6.5, | |
| "land_size": 2.0, | |
| "last_crop": "Onion", | |
| "crop": "Sesamum" | |
| } | |
| # Make the POST request | |
| response = requests.post(API_URL, json=test_data) | |
| # Print the response | |
| print("Status Code:", response.status_code) | |
| print("Response JSON:", response.json()) | |