Thibaut commited on
Commit
0bfed87
·
1 Parent(s): dec2100

added test files

Browse files
Files changed (3) hide show
  1. test.jpg +3 -0
  2. test_local.py +24 -0
  3. test_remote.py +21 -0
test.jpg ADDED

Git LFS Details

  • SHA256: 0dc5699c34dd9b56e7929fc225f3b9f100c3b1d6e12e78ec1eb91154373754b7
  • Pointer size: 131 Bytes
  • Size of remote file: 235 kB
test_local.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import json
3
+ from handler import EndpointHandler
4
+
5
+ # 1. Load the handler (loads SAM3 from ./model)
6
+ handler = EndpointHandler("model")
7
+
8
+ # 2. Load an image and convert to base64
9
+ with open("test.jpg", "rb") as f:
10
+ img_b64 = base64.b64encode(f.read()).decode("utf-8")
11
+
12
+ # 3. Build a fake HF request
13
+ payload = {
14
+ "inputs": img_b64,
15
+ "parameters": {
16
+ "classes": ["pothole", "marking"]
17
+ }
18
+ }
19
+
20
+ # 4. Run
21
+ output = handler(payload)
22
+
23
+ # 5. Print results
24
+ print(json.dumps(output, indent=2)[:2000]) # limit print to avoid huge logs
test_remote.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import base64
3
+
4
+ ENDPOINT = "https://YOUR-ENDPOINT"
5
+ TOKEN = "hf_xxx"
6
+
7
+ with open("test.jpg", "rb") as f:
8
+ img = base64.b64encode(f.read()).decode("utf-8")
9
+
10
+ payload = {
11
+ "inputs": img,
12
+ "parameters": {"classes": ["pothole", "marking"]}
13
+ }
14
+
15
+ r = requests.post(
16
+ ENDPOINT,
17
+ headers={"Authorization": f"Bearer {TOKEN}"},
18
+ json=payload
19
+ )
20
+
21
+ print(r.json())