Spaces:
Sleeping
Sleeping
devanshsrivastav
commited on
Merge pull request #4 from SudhanshuBlaze/SudhanshuDev
Browse files- EDxHuggingface.py +31 -29
EDxHuggingface.py
CHANGED
@@ -10,6 +10,7 @@ load_dotenv()
|
|
10 |
# AI model code
|
11 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
12 |
|
|
|
13 |
API_URL_ED = "https://api-inference.huggingface.co/models/bhadresh-savani/bert-base-go-emotion"
|
14 |
API_URL_HS = "https://api-inference.huggingface.co/models/IMSyPP/hate_speech_en"
|
15 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
@@ -29,36 +30,37 @@ def query(payload):
|
|
29 |
|
30 |
# Define color map for each emotion category
|
31 |
color_map = {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
}
|
61 |
|
|
|
62 |
# Labels for Hate Speech Classification
|
63 |
label_hs = {"LABEL_0": "Acceptable", "LABEL_1": "inappropriate", "LABEL_2": "Offensive", "LABEL_3": "Violent"}
|
64 |
|
@@ -106,7 +108,7 @@ with st.sidebar:
|
|
106 |
if submit:
|
107 |
|
108 |
# Call API and get predicted probabilities for each emotion category and hate speech classification
|
109 |
-
payload = {"inputs": text_input, "
|
110 |
response_ED, response_HS = query(payload)
|
111 |
predicted_probabilities_ED = response_ED[0]
|
112 |
predicted_probabilities_HS = response_HS[0]
|
|
|
10 |
# AI model code
|
11 |
HF_API_KEY = os.getenv("HF_API_KEY")
|
12 |
|
13 |
+
# API_URL_ED = "https://api-inference.huggingface.co/models/j-hartmann/emotion-english-distilroberta-base" #alternate ED model(slow loading on first run)
|
14 |
API_URL_ED = "https://api-inference.huggingface.co/models/bhadresh-savani/bert-base-go-emotion"
|
15 |
API_URL_HS = "https://api-inference.huggingface.co/models/IMSyPP/hate_speech_en"
|
16 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
|
|
30 |
|
31 |
# Define color map for each emotion category
|
32 |
color_map = {
|
33 |
+
'admiration': ['#1f77b4', '#98df8a', '#2ca02c', '#d62728'],
|
34 |
+
'amusement': ['#ff7f0e', '#98df8a', '#2ca02c', '#d62728'],
|
35 |
+
'anger': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
36 |
+
'annoyance': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
37 |
+
'approval': ['#1f77b4', '#98df8a', '#2ca02c', '#d62728'],
|
38 |
+
'caring': ['#98df8a', '#2ca02c', '#FF69B4', '#d62728'],
|
39 |
+
'confusion': ['#ffbb78', '#ff7f0e', '#9467bd', '#d62728'],
|
40 |
+
'curiosity': ['#ffbb78', '#ff7f0e', '#9467bd', '#d62728'],
|
41 |
+
'desire': ['#2ca02c', '#ff7f0e', '#98df8a', '#d62728'],
|
42 |
+
'disappointment': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
43 |
+
'disapproval': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
44 |
+
'disgust': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
45 |
+
'embarrassment': ['#ffbb78', '#ff7f0e', '#9467bd', '#d62728'],
|
46 |
+
'excitement': ['#ff7f0e', '#2ca02c', '#98df8a', '#d62728'],
|
47 |
+
'fear': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
48 |
+
'gratitude': ['#98df8a', '#2ca02c', '#1f77b4', '#d62728'],
|
49 |
+
'grief': ['#ffbb78', '#d62728', '#bcbd22', '#ff7f0e'],
|
50 |
+
'joy': ['#ff7f0e', '#98df8a', '#2ca02c', '#d62728'],
|
51 |
+
'love': ['#FF69B4', '#98df8a', '#2ca02c', '#d62728'],
|
52 |
+
'nervousness': ['#ffbb78', '#ff7f0e', '#9467bd', '#d62728'],
|
53 |
+
'optimism': ['#98df8a', '#2ca02c', '#1f77b4', '#d62728'],
|
54 |
+
'pride': ['#98df8a', '#ff7f0e', '#1f77b4', '#d62728'],
|
55 |
+
'realization': ['#9467bd', '#ff7f0e', '#ffbb78', '#d62728'],
|
56 |
+
'relief': ['#1f77b4', '#98df8a', '#2ca02c', '#d62728'],
|
57 |
+
'remorse': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
58 |
+
'sadness': ['#ffbb78', '#ff7f0e', '#d62728', '#bcbd22'],
|
59 |
+
'surprise': ['#ff7f0e', '#ffbb78', '#9467bd', '#d62728'],
|
60 |
+
'neutral': ['#2ca02c', '#98df8a', '#1f77b4', '#d62728']
|
61 |
}
|
62 |
|
63 |
+
|
64 |
# Labels for Hate Speech Classification
|
65 |
label_hs = {"LABEL_0": "Acceptable", "LABEL_1": "inappropriate", "LABEL_2": "Offensive", "LABEL_3": "Violent"}
|
66 |
|
|
|
108 |
if submit:
|
109 |
|
110 |
# Call API and get predicted probabilities for each emotion category and hate speech classification
|
111 |
+
payload = {"inputs": text_input, "options": {"wait_for_model": True, "use_cache": True}}
|
112 |
response_ED, response_HS = query(payload)
|
113 |
predicted_probabilities_ED = response_ED[0]
|
114 |
predicted_probabilities_HS = response_HS[0]
|