Spaces:
Runtime error
Runtime error
Rob Caamano
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ model_name = ""
|
|
| 17 |
with st.container():
|
| 18 |
model_name = st.selectbox(
|
| 19 |
"Select Model",
|
| 20 |
-
("RobCaamano/toxicity",),
|
| 21 |
)
|
| 22 |
submit = st.button("Submit", type="primary")
|
| 23 |
|
|
@@ -31,21 +31,32 @@ input = tokenizer(text, return_tensors="tf")
|
|
| 31 |
|
| 32 |
if submit:
|
| 33 |
results = dict(d.values() for d in clf(text)[0])
|
| 34 |
-
classes = {k: results[k] for k in results.keys() if not k == "toxic"}
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
if results['toxic'] >= 0.5:
|
| 40 |
-
result_df = pd.DataFrame({
|
| 41 |
-
'Toxic': ['Yes'],
|
| 42 |
-
'Toxicity Class': [max_class],
|
| 43 |
-
'Probability': [probability]
|
| 44 |
-
})
|
| 45 |
-
else:
|
| 46 |
result_df = pd.DataFrame({
|
| 47 |
-
'
|
| 48 |
-
'
|
| 49 |
})
|
| 50 |
|
| 51 |
st.table(result_df)
|
|
|
|
| 17 |
with st.container():
|
| 18 |
model_name = st.selectbox(
|
| 19 |
"Select Model",
|
| 20 |
+
("RobCaamano/toxicity", "distilbert-base-uncased-finetuned-sst-2-english"),
|
| 21 |
)
|
| 22 |
submit = st.button("Submit", type="primary")
|
| 23 |
|
|
|
|
| 31 |
|
| 32 |
if submit:
|
| 33 |
results = dict(d.values() for d in clf(text)[0])
|
|
|
|
| 34 |
|
| 35 |
+
if model_name == "RobCaamano/toxicity":
|
| 36 |
+
classes = {k: results[k] for k in results.keys() if not k == "toxic"}
|
| 37 |
+
|
| 38 |
+
max_class = max(classes, key=classes.get)
|
| 39 |
+
probability = classes[max_class]
|
| 40 |
+
|
| 41 |
+
if results['toxic'] >= 0.5:
|
| 42 |
+
result_df = pd.DataFrame({
|
| 43 |
+
'Toxic': ['Yes'],
|
| 44 |
+
'Toxicity Class': [max_class],
|
| 45 |
+
'Probability': [probability]
|
| 46 |
+
})
|
| 47 |
+
else:
|
| 48 |
+
result_df = pd.DataFrame({
|
| 49 |
+
'Toxic': ['No'],
|
| 50 |
+
'Toxicity Class': 'This text is not toxic',
|
| 51 |
+
})
|
| 52 |
+
|
| 53 |
+
elif model_name == "distilbert-base-uncased-finetuned-sst-2-english":
|
| 54 |
+
result = max(results, key=results.get)
|
| 55 |
+
probability = results[result]
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
result_df = pd.DataFrame({
|
| 58 |
+
'Result': [result],
|
| 59 |
+
'Probability': [probability],
|
| 60 |
})
|
| 61 |
|
| 62 |
st.table(result_df)
|