ilan541 commited on
Commit
5d34d7c
·
1 Parent(s): 07a6335

initial commit

Browse files

given a string of the format "ssid" + "OUI", classifies the input among the following list: ['Bus', 'Portable Device', 'Stationary Device', 'Vehicle'].

Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
3
+ import gradio as gr
4
+ import numpy as np
5
+ from scipy.special import softmax
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained('roberta-base')
8
+
9
+ from transformers import TFAutoModelForSequenceClassification
10
+ model = TFAutoModelForSequenceClassification.from_pretrained("ilan541/ssid_classification")
11
+
12
+
13
+ def get_probs(text):
14
+ inp = tokenizer(text,
15
+ truncation=True,
16
+ padding='max_length',
17
+ max_length=30,
18
+ return_tensors='tf')
19
+ y_pred = model(inp)
20
+
21
+ return y_pred.logits
22
+
23
+
24
+ def predict(your_text):
25
+
26
+ y_pred_logits = get_probs(your_text)
27
+ labels = ['Bus', 'Portable Device', 'Stationary Device', 'Vehicle']
28
+
29
+ # print logits
30
+ for label, logit in zip(labels, y_pred_logits):
31
+ print(f"logit - {label}: {logit}")
32
+
33
+ # print probas
34
+ y_probs = softmax(y_pred_logits)
35
+ for label, prob in zip(labels, y_probs):
36
+ print(f"prob - {label}: {prob}")
37
+
38
+ # print predicted class
39
+ i = np.argmax(y_pred_logits)
40
+ print(f"Predicted class: {labels[i]} with proba {y_probs[i]}')
41
+
42
+
43
+ iface = gr.Interface(fn=predict, inputs="text", outputs="text")
44
+ iface.launch()