offlinedemo 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {offlinedemo-0.1.0 → offlinedemo-0.2.0}/PKG-INFO +1 -1
- {offlinedemo-0.1.0 → offlinedemo-0.2.0}/pyproject.toml +1 -1
- {offlinedemo-0.1.0 → offlinedemo-0.2.0}/pyproject.toml.orig +1 -1
- {offlinedemo-0.1.0 → offlinedemo-0.2.0}/src/offlinedemo/__init__.py +14 -3
- {offlinedemo-0.1.0 → offlinedemo-0.2.0}/README.md +0 -0
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
# Copyright (c) 2026- offlineisbetter
|
|
3
3
|
|
|
4
4
|
from pathlib import Path
|
|
5
|
+
import json
|
|
5
6
|
import sys
|
|
6
7
|
import time
|
|
7
8
|
|
|
9
|
+
import numpy as np
|
|
8
10
|
from transformers import AutoTokenizer
|
|
9
11
|
import onnxruntime as ort
|
|
10
12
|
|
|
11
13
|
def main():
|
|
12
14
|
# Get checkpoint name
|
|
13
15
|
if len(sys.argv) < 2:
|
|
14
|
-
print("offlinedemo [checkpoint]")
|
|
16
|
+
print("offlinedemo [checkpoint-dir]")
|
|
15
17
|
return
|
|
16
18
|
checkpoint = Path(sys.argv[1])
|
|
17
19
|
|
|
@@ -21,13 +23,19 @@ def main():
|
|
|
21
23
|
providers=["CPUExecutionProvider"],
|
|
22
24
|
)
|
|
23
25
|
print("Model loaded!")
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
# Load classes
|
|
28
|
+
with open(checkpoint / "offlineisbetter.json", "r") as f:
|
|
29
|
+
classes = json.load(f)
|
|
30
|
+
classes = {v: k for k, v in classes.items()}
|
|
25
31
|
|
|
26
32
|
# Load tokenizer
|
|
27
33
|
tokenizer = AutoTokenizer.from_pretrained(
|
|
28
34
|
checkpoint,
|
|
29
35
|
local_files_only = True,
|
|
30
36
|
)
|
|
37
|
+
print("Tokenizer loaded!")
|
|
38
|
+
print()
|
|
31
39
|
|
|
32
40
|
# Ask user for input
|
|
33
41
|
user_input = input("offlineisbetter >> ")
|
|
@@ -35,9 +43,12 @@ def main():
|
|
|
35
43
|
# Tokenize and run inference
|
|
36
44
|
start = time.perf_counter()
|
|
37
45
|
tokens = tokenizer(user_input)
|
|
38
|
-
result = session.run(None, tokens)[0]
|
|
46
|
+
result = session.run(None, tokens)[0][0]
|
|
47
|
+
idx = int(np.argmax(result))
|
|
48
|
+
c = classes[idx]
|
|
39
49
|
duration = time.perf_counter() - start
|
|
40
50
|
|
|
41
51
|
# Report to user
|
|
42
52
|
print(f"LOGITS: {result}")
|
|
53
|
+
print(f"CLASS: {c}")
|
|
43
54
|
print(f"LATENCY: {duration*1000:.3f} ms")
|
|
File without changes
|