devanshsrivastav commited on
Commit
dd67db3
2 Parent(s): 55a9445 49cae18

Merge pull request #4 from SudhanshuBlaze/SudhanshuDev

Browse files
Files changed (1) hide show
  1. 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
- 'admiration': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
33
- 'amusement': ['#ff7f0e', '#ffbb78', '#2ca02c', '#d62728'],
34
- 'anger': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
35
- 'annoyance': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
36
- 'approval': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
37
- 'caring': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
38
- 'confusion': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
39
- 'curiosity': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
40
- 'desire': ['#ff7f0e', '#ffbb78', '#2ca02c', '#d62728'],
41
- 'disappointment': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
42
- 'disapproval': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
43
- 'disgust': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
44
- 'embarrassment': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
45
- 'excitement': ['#ff7f0e', '#ffbb78', '#2ca02c', '#d62728'],
46
- 'fear': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
47
- 'gratitude': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
48
- 'grief': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
49
- 'joy': ['#ff7f0e', '#ffbb78', '#2ca02c', '#d62728'],
50
- 'love': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
51
- 'nervousness': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
52
- 'optimism': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
53
- 'pride': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
54
- 'realization': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
55
- 'relief': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728'],
56
- 'remorse': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
57
- 'sadness': ['#d62728', '#ff9896', '#2ca02c', '#bcbd22'],
58
- 'surprise': ['#9467bd', '#c5b0d5', '#ff7f0e', '#d62728'],
59
- 'neutral': ['#1f77b4', '#aec7e8', '#ff7f0e', '#d62728']
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, "use_cache": True, "wait_for_model": True}
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]