Spaces:
Runtime error
Runtime error
Victoria Reis
commited on
Commit
•
d4a0f6d
1
Parent(s):
0b0b452
feature:chart visualization
Browse files- app.py +26 -25
- flagged/log.csv +2 -0
app.py
CHANGED
@@ -4,9 +4,10 @@ import torch
|
|
4 |
from collections import Counter
|
5 |
from scipy.special import softmax
|
6 |
import plotly.express as px
|
|
|
7 |
|
8 |
# Article string
|
9 |
-
article_string = "
|
10 |
|
11 |
# App title
|
12 |
app_title = "Portuguese hate speech identifier (Multiclass) - Identificador de discurso de ódio em português (Multiclasse)"
|
@@ -97,8 +98,6 @@ def most_frequent(array):
|
|
97 |
occurence_count = Counter(array)
|
98 |
return occurence_count.most_common(1)[0][0]
|
99 |
|
100 |
-
|
101 |
-
# Prediction function
|
102 |
def predict(s1, chosen_model):
|
103 |
# Clear previous figure instance
|
104 |
fig = None
|
@@ -133,21 +132,23 @@ def predict(s1, chosen_model):
|
|
133 |
# Get the categories and probabilities for all classes
|
134 |
all_categories = [hate_speech_categories[index] for index in valid_indices]
|
135 |
all_probabilities = [logits[index] for index in valid_indices]
|
136 |
-
|
137 |
-
# Create a bar plot using Plotly
|
138 |
fig = px.bar(x=all_categories, y=all_probabilities, labels={'x': 'Categories', 'y': 'Probabilities'},
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
#
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
151 |
|
152 |
# Input components
|
153 |
inputs = [
|
@@ -155,14 +156,14 @@ inputs = [
|
|
155 |
gr.Dropdown(label="Model", choices=user_friendly_name_list, value=user_friendly_name_list[0])
|
156 |
]
|
157 |
|
158 |
-
# Output components
|
159 |
outputs = [
|
160 |
-
gr.
|
161 |
-
gr.Label(label="Probability"),
|
162 |
]
|
163 |
|
164 |
-
# Gradio interface
|
165 |
-
gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title=app_title,
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
4 |
from collections import Counter
|
5 |
from scipy.special import softmax
|
6 |
import plotly.express as px
|
7 |
+
import plotly.io as pio # Add this import
|
8 |
|
9 |
# Article string
|
10 |
+
article_string = "Authors: <a href=\"https://huggingface.co/FpOliveira\">Felipe Oliveira</a> & <a href=\"https://huggingface.co/victoriadreis\">Victoria Reis</a>. Read more about our <a href=\"https://github.com/Silly-Machine/TuPi-Portuguese-Hate-Speech-Dataset\">The Portuguese hate speech dataset (TuPI) </a>."
|
11 |
|
12 |
# App title
|
13 |
app_title = "Portuguese hate speech identifier (Multiclass) - Identificador de discurso de ódio em português (Multiclasse)"
|
|
|
98 |
occurence_count = Counter(array)
|
99 |
return occurence_count.most_common(1)[0][0]
|
100 |
|
|
|
|
|
101 |
def predict(s1, chosen_model):
|
102 |
# Clear previous figure instance
|
103 |
fig = None
|
|
|
132 |
# Get the categories and probabilities for all classes
|
133 |
all_categories = [hate_speech_categories[index] for index in valid_indices]
|
134 |
all_probabilities = [logits[index] for index in valid_indices]
|
135 |
+
|
|
|
136 |
fig = px.bar(x=all_categories, y=all_probabilities, labels={'x': 'Categories', 'y': 'Probabilities'},
|
137 |
+
title=" ",
|
138 |
+
text=all_probabilities, color_discrete_sequence=['#ff7400'])
|
139 |
+
|
140 |
+
fig.update_traces(texttemplate='%{text:.2f}', textposition='outside')
|
141 |
+
|
142 |
+
# Rotate the text in x-axis by 90 degrees
|
143 |
+
fig.update_layout(xaxis_tickangle=-90)
|
144 |
+
|
145 |
+
# Increase the space around the chart
|
146 |
+
fig.update_layout(margin=dict(l=50, r=50, b=100, t=100))
|
147 |
+
|
148 |
+
# Set the y-axis range to go up to 1.1
|
149 |
+
fig.update_layout(yaxis=dict(range=[0, 1.1]))
|
150 |
+
|
151 |
+
return fig
|
152 |
|
153 |
# Input components
|
154 |
inputs = [
|
|
|
156 |
gr.Dropdown(label="Model", choices=user_friendly_name_list, value=user_friendly_name_list[0])
|
157 |
]
|
158 |
|
|
|
159 |
outputs = [
|
160 |
+
gr.Plot(label="Classes Predicted Probabilities") # Add this line
|
|
|
161 |
]
|
162 |
|
163 |
+
# Gradio interface without launching
|
164 |
+
interface = gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title=app_title,
|
165 |
+
description=app_description, examples=app_examples, article=article_string, live=False)
|
166 |
+
|
167 |
+
# Launch the interface
|
168 |
+
interface.launch()
|
169 |
+
|
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Text,Model,Predominant category,Probability,flag,username,timestamp
|
2 |
+
mds mas o viado vir responder meus status falando q a taylor foi racista foi o auge 😂😂,BERTimbau large (TuPi),"{""label"":null,""confidences"":null}","{""label"":null,""confidences"":null}",,,2023-12-04 14:13:25.289476
|