KeeganFdes commited on
Commit
6dd247c
1 Parent(s): d94c9cb

version alpha

Browse files
Files changed (4) hide show
  1. app.py +32 -0
  2. classes.pkl +3 -0
  3. requirements.txt +2 -0
  4. tokenizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import onnxruntime
3
+ import numpy as np
4
+ import pickle
5
+ threshold = 0.5
6
+ onnx_session = onnxruntime.InferenceSession("bert.onnx")
7
+
8
+ # Load the instance back
9
+ with open('classes.pkl', 'rb') as file:
10
+ mlb = pickle.load(file)
11
+
12
+ with open('tokenizer.pkl', 'rb') as file:
13
+ tokenizer = pickle.load(file)
14
+
15
+
16
+ # Create a function to predict tags using the ONNX model
17
+ def predict_tags_onnx(text):
18
+ encoded_text = tokenizer(text , padding=True, truncation=True, return_tensors='pt')
19
+ input_ids = encoded_text["input_ids"].numpy()
20
+ attention_mask = encoded_text["attention_mask"].numpy()
21
+
22
+ # Run the ONNX model
23
+ outputs = np.asarray(onnx_session.run(None, {"input_ids": input_ids , "attention_mask":attention_mask}))
24
+
25
+ # Post-process the outputs as needed
26
+ #predicted_labels = torch.sigmoid(outputs).cpu().numpy()
27
+ predicted_tags = mlb.classes_[np.where(np.squeeze((outputs > threshold).astype(int)).flatten() == 1)]
28
+
29
+ return predicted_tags
30
+
31
+ iface = gr.Interface(fn=predict_tags_onnx, inputs="text", outputs="text")
32
+ iface.launch()
classes.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:203390ce8d1e08f4ce6f73a1216738464c89d23caec7ec32e122936a26a90412
3
+ size 922
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ onnxruntime
2
+ pytorch
tokenizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:add9a91ca5f8f6831904391f6f9b37477fbd1b36ece1032c100b42810a930951
3
+ size 628896