ilan541 commited on
Commit
d430ce1
·
1 Parent(s): 02050c0

Update app.py

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