Spaces:
Runtime error
Runtime error
Rob Caamano
commited on
App RObert
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ if selected_model == "Fine-tuned Toxicity Model":
|
|
| 26 |
toxicity_classes = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
|
| 27 |
model.config.id2label = {i: toxicity_classes[i] for i in range(model.config.num_labels)}
|
| 28 |
|
| 29 |
-
def
|
| 30 |
max_index = prediction.argmax()
|
| 31 |
return model.config.id2label[max_index], prediction[max_index]
|
| 32 |
|
|
@@ -34,23 +34,24 @@ input = tokenizer(text, return_tensors="tf")
|
|
| 34 |
prediction = model(input)[0].numpy()[0]
|
| 35 |
|
| 36 |
if st.button("Submit", type="primary"):
|
| 37 |
-
label, probability =
|
| 38 |
|
| 39 |
tweet_portion = text[:50] + "..." if len(text) > 50 else text
|
| 40 |
|
| 41 |
if selected_model == "Fine-tuned Toxicity Model":
|
| 42 |
-
column_name = "
|
| 43 |
else:
|
| 44 |
column_name = "Prediction"
|
| 45 |
|
| 46 |
if probability < 0.1:
|
| 47 |
st.write("This tweet is not toxic.")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
| 26 |
toxicity_classes = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
|
| 27 |
model.config.id2label = {i: toxicity_classes[i] for i in range(model.config.num_labels)}
|
| 28 |
|
| 29 |
+
def get_toxicity_class(prediction):
|
| 30 |
max_index = prediction.argmax()
|
| 31 |
return model.config.id2label[max_index], prediction[max_index]
|
| 32 |
|
|
|
|
| 34 |
prediction = model(input)[0].numpy()[0]
|
| 35 |
|
| 36 |
if st.button("Submit", type="primary"):
|
| 37 |
+
label, probability = get_toxicity_class(prediction)
|
| 38 |
|
| 39 |
tweet_portion = text[:50] + "..." if len(text) > 50 else text
|
| 40 |
|
| 41 |
if selected_model == "Fine-tuned Toxicity Model":
|
| 42 |
+
column_name = "Toxicity Class"
|
| 43 |
else:
|
| 44 |
column_name = "Prediction"
|
| 45 |
|
| 46 |
if probability < 0.1:
|
| 47 |
st.write("This tweet is not toxic.")
|
| 48 |
+
else:
|
| 49 |
+
df = pd.DataFrame(
|
| 50 |
+
{
|
| 51 |
+
"Tweet (portion)": [tweet_portion],
|
| 52 |
+
column_name: [label],
|
| 53 |
+
"Probability": [probability],
|
| 54 |
+
}
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
st.table(df)
|