Download test_predict.py from Neptune9728/sound-insight-api: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/Neptune9728/sound-insight-api/resolve/main/test_predict.py
- Command line
-
hf download hf://spaces/Neptune9728/sound-insight-api/test_predict.py
-
curl -L -o test_predict.py https://huggingface.co/spaces/Neptune9728/sound-insight-api/resolve/main/test_predict.py
977 Bytes
| import argparse | |
| import json | |
| import requests | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--url", default="http://127.0.0.1:8000/predict") | |
| parser.add_argument("--model", choices=["cat", "baby", "dog"], required=True) | |
| parser.add_argument("--audio", required=True) | |
| parser.add_argument("--model-version", default="bundled") | |
| parser.add_argument( | |
| "--guard-mode", | |
| choices=["balanced", "relaxed", "off", "strict"], | |
| default="balanced", | |
| ) | |
| args = parser.parse_args() | |
| with open(args.audio, "rb") as audio_file: | |
| response = requests.post( | |
| args.url, | |
| data={ | |
| "model": args.model, | |
| "model_version": args.model_version, | |
| "guard_mode": args.guard_mode, | |
| }, | |
| files={"audio": (args.audio, audio_file, "application/octet-stream")}, | |
| timeout=180, | |
| ) | |
| print(response.status_code) | |
| try: | |
| print(json.dumps(response.json(), ensure_ascii=False, indent=2)) | |
| except ValueError: | |
| print(response.text) | |