Spaces:
Sleeping
Sleeping
vickeee465
commited on
Commit
·
50c2025
1
Parent(s):
b82d609
fixed id2label issue
Browse files
app.py
CHANGED
@@ -17,6 +17,14 @@ HF_TOKEN = os.environ["hf_read"]
|
|
17 |
SENTIMENT_LABEL_NAMES = {0: "Negative", 1: "No sentiment or Neutral sentiment", 2: "Positive"}
|
18 |
LANGUAGES = ["Czech", "English", "French", "German", "Hungarian", "Polish", "Slovakian"]
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def load_spacy_model(model_name="xx_sent_ud_sm"):
|
21 |
try:
|
22 |
model = spacy.load(model_name)
|
@@ -58,7 +66,7 @@ def predict(text, model_id, tokenizer_id):
|
|
58 |
return probs
|
59 |
|
60 |
def get_most_probable_label(probs):
|
61 |
-
label =
|
62 |
probability = f"{round(100 * probs.max(), 2)}%"
|
63 |
return [sentence, label, probability]
|
64 |
|
|
|
17 |
SENTIMENT_LABEL_NAMES = {0: "Negative", 1: "No sentiment or Neutral sentiment", 2: "Positive"}
|
18 |
LANGUAGES = ["Czech", "English", "French", "German", "Hungarian", "Polish", "Slovakian"]
|
19 |
|
20 |
+
id2label = {
|
21 |
+
0: "Anger",
|
22 |
+
1: "Fear",
|
23 |
+
2: "Disgust",
|
24 |
+
3: "Sadness",
|
25 |
+
4: "Joy",
|
26 |
+
5: "None of Them"
|
27 |
+
}
|
28 |
def load_spacy_model(model_name="xx_sent_ud_sm"):
|
29 |
try:
|
30 |
model = spacy.load(model_name)
|
|
|
66 |
return probs
|
67 |
|
68 |
def get_most_probable_label(probs):
|
69 |
+
label = id2label[probs.argmax()]
|
70 |
probability = f"{round(100 * probs.max(), 2)}%"
|
71 |
return [sentence, label, probability]
|
72 |
|