Spaces:
Running
Running
dict unhasable error fix
Browse files- interfaces/sentiment.py +3 -2
interfaces/sentiment.py
CHANGED
@@ -40,8 +40,9 @@ def predict(text, model_id, tokenizer_id):
|
|
40 |
|
41 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
42 |
output_pred = {model.config.id2label[i]: probs[i] for i in np.argsort(probs)[::-1]}
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
|
47 |
return output_pred, output_info
|
|
|
40 |
|
41 |
probs = torch.nn.functional.softmax(logits, dim=1).cpu().numpy().flatten()
|
42 |
output_pred = {model.config.id2label[i]: probs[i] for i in np.argsort(probs)[::-1]}
|
43 |
+
|
44 |
+
predicted_label = max(output_pred, key=output_pred.get)
|
45 |
+
output_pred = {4: 2, 5: 1}.get(predicted_label, 0)
|
46 |
|
47 |
output_info = f'<p style="text-align: center; display: block">Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.</p>'
|
48 |
return output_pred, output_info
|