update
Browse files- tests/test_api.ipynb +70 -0
tests/test_api.ipynb
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 30,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"[[{'label': 'debug', 'score': 0.1}]]\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"import requests\n",
|
18 |
+
"import numpy as np\n",
|
19 |
+
"import json\n",
|
20 |
+
"\n",
|
21 |
+
"API_URL = \"https://api-inference.huggingface.co/models/zhuwq/PhaseNet\"\n",
|
22 |
+
"# API_URL = \"https://api-inference.huggingface.co/models/zhuwq/test-model\"\n",
|
23 |
+
"headers = {\"Authorization\": \"Bearer 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\"}\n",
|
24 |
+
"\n",
|
25 |
+
"def query(payload):\n",
|
26 |
+
" response = requests.post(API_URL, headers=headers, json=payload)\n",
|
27 |
+
" return response.json()\n",
|
28 |
+
" # return json.loads(response.content.decode(\"utf-8\"))\n",
|
29 |
+
"\n",
|
30 |
+
"array = np.random.rand(10, 3).tolist()\n",
|
31 |
+
"inputs = json.dumps(array)\n",
|
32 |
+
"data = {\n",
|
33 |
+
"\t# \"inputs\": \"I like you. I love you\",\n",
|
34 |
+
" \"inputs\": inputs,\n",
|
35 |
+
" \"options\":{\"wait_for_model\": True},\n",
|
36 |
+
"}\n",
|
37 |
+
"\n",
|
38 |
+
"output = query(data)\n",
|
39 |
+
"print(output)"
|
40 |
+
]
|
41 |
+
}
|
42 |
+
],
|
43 |
+
"metadata": {
|
44 |
+
"kernelspec": {
|
45 |
+
"display_name": "base",
|
46 |
+
"language": "python",
|
47 |
+
"name": "python3"
|
48 |
+
},
|
49 |
+
"language_info": {
|
50 |
+
"codemirror_mode": {
|
51 |
+
"name": "ipython",
|
52 |
+
"version": 3
|
53 |
+
},
|
54 |
+
"file_extension": ".py",
|
55 |
+
"mimetype": "text/x-python",
|
56 |
+
"name": "python",
|
57 |
+
"nbconvert_exporter": "python",
|
58 |
+
"pygments_lexer": "ipython3",
|
59 |
+
"version": "3.9.13"
|
60 |
+
},
|
61 |
+
"orig_nbformat": 4,
|
62 |
+
"vscode": {
|
63 |
+
"interpreter": {
|
64 |
+
"hash": "0efb5d07c150d814a79610ed835fac9f37a29f75f64726a0e33cb3dca03bca5e"
|
65 |
+
}
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"nbformat": 4,
|
69 |
+
"nbformat_minor": 2
|
70 |
+
}
|