Spaces:
Runtime error
Runtime error
devanshsrivastav
commited on
Commit
·
2e5c355
1
Parent(s):
c499248
removed normalised scores
Browse files
app.py
CHANGED
@@ -17,6 +17,12 @@ API_URL_SD = "https://api-inference.huggingface.co/models/NLP-LTU/bertweet-large
|
|
17 |
|
18 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
st.set_page_config(
|
21 |
page_title="GoEmotions Dashboard",
|
22 |
layout="wide"
|
@@ -25,12 +31,6 @@ st.set_page_config(
|
|
25 |
# Set page title
|
26 |
st.title("GoEmotions Dashboard - Analyzing Emotions in Text")
|
27 |
|
28 |
-
def query(payload):
|
29 |
-
response_ED = requests.request("POST", API_URL_ED, headers=headers, json=payload)
|
30 |
-
response_HS = requests.request("POST", API_URL_HS, headers=headers, json=payload)
|
31 |
-
response_SD = requests.request("POST", API_URL_SD, headers=headers, json=payload)
|
32 |
-
return (json.loads(response_ED.content.decode("utf-8")),json.loads(response_HS.content.decode("utf-8")),json.loads(response_SD.content.decode("utf-8")))
|
33 |
-
|
34 |
# Define color map for each emotion category
|
35 |
color_map = {
|
36 |
'admiration': ['#1f77b4', '#98df8a', '#2ca02c', '#d62728'],
|
@@ -87,8 +87,8 @@ default_options = [
|
|
87 |
with st.sidebar:
|
88 |
|
89 |
# Add page description
|
90 |
-
description = "The GoEmotions Dashboard is a web-based user interface for analyzing emotions in text. The dashboard is powered by
|
91 |
-
|
92 |
|
93 |
# Create dropdown with default options
|
94 |
selected_option = st.selectbox("Select a default option or enter your own text:", default_options)
|
@@ -117,11 +117,7 @@ if submit:
|
|
117 |
top_emotions = predicted_probabilities_ED[:4]
|
118 |
top_scores = [e['score'] for e in top_emotions]
|
119 |
|
120 |
-
#
|
121 |
-
total = sum(top_scores)
|
122 |
-
normalized_scores = [score/total * 100 for score in top_scores]
|
123 |
-
|
124 |
-
# Create the gauge charts for the top 4 emotion categories using the normalized scores
|
125 |
fig = make_subplots(rows=2, cols=2, specs=[[{'type': 'indicator'}, {'type': 'indicator'}],
|
126 |
[{'type': 'indicator'}, {'type': 'indicator'}]],
|
127 |
vertical_spacing=0.4)
|
@@ -130,7 +126,7 @@ if submit:
|
|
130 |
# Get the emotion category, color, and normalized score for the current emotion
|
131 |
category = emotion['label']
|
132 |
color = color_map[category]
|
133 |
-
value =
|
134 |
|
135 |
# Calculate the row and column position for adding the trace to the subplots
|
136 |
row = i // 2 + 1
|
@@ -187,12 +183,12 @@ if submit:
|
|
187 |
st.text("")
|
188 |
|
189 |
with SD:
|
|
|
190 |
st.text("")
|
191 |
st.text("")
|
192 |
st.text("")
|
193 |
st.subheader("Sexism Detection")
|
194 |
st.text("")
|
195 |
-
label_SD = predicted_probabilities_SD[0]['label'].title()
|
196 |
st.image(f"assets/{label_SD}.jpg", width=200)
|
197 |
st.text("")
|
198 |
st.text("")
|
|
|
17 |
|
18 |
headers = {"Authorization": f"Bearer {HF_API_KEY}"}
|
19 |
|
20 |
+
def query(payload):
|
21 |
+
response_ED = requests.request("POST", API_URL_ED, headers=headers, json=payload)
|
22 |
+
response_HS = requests.request("POST", API_URL_HS, headers=headers, json=payload)
|
23 |
+
response_SD = requests.request("POST", API_URL_SD, headers=headers, json=payload)
|
24 |
+
return (json.loads(response_ED.content.decode("utf-8")),json.loads(response_HS.content.decode("utf-8")),json.loads(response_SD.content.decode("utf-8")))
|
25 |
+
|
26 |
st.set_page_config(
|
27 |
page_title="GoEmotions Dashboard",
|
28 |
layout="wide"
|
|
|
31 |
# Set page title
|
32 |
st.title("GoEmotions Dashboard - Analyzing Emotions in Text")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Define color map for each emotion category
|
35 |
color_map = {
|
36 |
'admiration': ['#1f77b4', '#98df8a', '#2ca02c', '#d62728'],
|
|
|
87 |
with st.sidebar:
|
88 |
|
89 |
# Add page description
|
90 |
+
description = "The GoEmotions Dashboard is a web-based user interface for analyzing emotions in text. The dashboard is powered by pre-trained natural language processing models that can detect emotions, identify hatespeech and sexist speech in text input. This dashboard is useful for anyone who wants to understand the emotional content of a text, including content creators, marketers, and researchers."
|
91 |
+
st.markdown(description)
|
92 |
|
93 |
# Create dropdown with default options
|
94 |
selected_option = st.selectbox("Select a default option or enter your own text:", default_options)
|
|
|
117 |
top_emotions = predicted_probabilities_ED[:4]
|
118 |
top_scores = [e['score'] for e in top_emotions]
|
119 |
|
120 |
+
# Create the gauge charts for the top 4 emotion categories
|
|
|
|
|
|
|
|
|
121 |
fig = make_subplots(rows=2, cols=2, specs=[[{'type': 'indicator'}, {'type': 'indicator'}],
|
122 |
[{'type': 'indicator'}, {'type': 'indicator'}]],
|
123 |
vertical_spacing=0.4)
|
|
|
126 |
# Get the emotion category, color, and normalized score for the current emotion
|
127 |
category = emotion['label']
|
128 |
color = color_map[category]
|
129 |
+
value = top_scores[i] * 100
|
130 |
|
131 |
# Calculate the row and column position for adding the trace to the subplots
|
132 |
row = i // 2 + 1
|
|
|
183 |
st.text("")
|
184 |
|
185 |
with SD:
|
186 |
+
label_SD = predicted_probabilities_SD[0]['label'].title()
|
187 |
st.text("")
|
188 |
st.text("")
|
189 |
st.text("")
|
190 |
st.subheader("Sexism Detection")
|
191 |
st.text("")
|
|
|
192 |
st.image(f"assets/{label_SD}.jpg", width=200)
|
193 |
st.text("")
|
194 |
st.text("")
|