DzmitryXXL commited on
Commit
c94eabd
·
1 Parent(s): d9a9e61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -11,6 +11,9 @@ label_encoder = joblib.load('WSP_label_encoder.joblib')
11
 
12
  input_phrase = st.text_input("Input search text")
13
 
 
 
 
14
  if input_phrase:
15
  tokenized_input = tokenizer(input_phrase, truncation=True, padding=True, return_tensors='pt')
16
 
@@ -18,6 +21,10 @@ if input_phrase:
18
  outputs = loaded_model(**tokenized_input)
19
 
20
  predicted_class = torch.argmax(outputs.logits, dim=1).item()
21
- predicted_category = label_encoder.inverse_transform([predicted_class])[0]
22
 
23
- st.text(f"Output: {predicted_category}")
 
 
 
 
 
11
 
12
  input_phrase = st.text_input("Input search text")
13
 
14
+ # Добавляем слайдер для выбора вероятности
15
+ confidence_threshold = st.slider("Confidence Threshold (%)", 0, 100, 50)
16
+
17
  if input_phrase:
18
  tokenized_input = tokenizer(input_phrase, truncation=True, padding=True, return_tensors='pt')
19
 
 
21
  outputs = loaded_model(**tokenized_input)
22
 
23
  predicted_class = torch.argmax(outputs.logits, dim=1).item()
24
+ predicted_confidence = torch.softmax(outputs.logits, dim=1)[0][predicted_class].item() * 100
25
 
26
+ if predicted_confidence >= confidence_threshold:
27
+ predicted_category = label_encoder.inverse_transform([predicted_class])[0]
28
+ st.text(f"Output: {predicted_category}")
29
+ else:
30
+ st.text(f"Output: {input_phrase}")