Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,18 +3,18 @@ import transformers
|
|
| 3 |
import torch
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
st.title("Toxicity
|
| 7 |
|
| 8 |
# Set default text
|
| 9 |
default_text = "Cody Jiang is a fantastic student in CS-UY-4613!"
|
| 10 |
|
| 11 |
-
# Select model
|
| 12 |
-
model_names = ['
|
| 13 |
-
model_name = st.selectbox("Select a model", model_names)
|
| 14 |
|
| 15 |
-
# Load selected model
|
| 16 |
if model_name == 'Codys Finetuning Language Model':
|
| 17 |
-
model_path = 'model'
|
| 18 |
else:
|
| 19 |
model_path = model_name
|
| 20 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_path)
|
|
@@ -34,11 +34,7 @@ if st.button("Submit"):
|
|
| 34 |
inputs = inputs.to(device)
|
| 35 |
outputs = model(**inputs)
|
| 36 |
logits = outputs.logits
|
| 37 |
-
probabilities = torch.sigmoid(logits).detach().cpu().numpy()
|
| 38 |
-
predictions =
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
df = pd.DataFrame(data)
|
| 42 |
-
|
| 43 |
-
st.success("Toxicity Analysis Results:")
|
| 44 |
-
st.table(df)
|
|
|
|
| 3 |
import torch
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
+
st.title("Toxicity Classification App")
|
| 7 |
|
| 8 |
# Set default text
|
| 9 |
default_text = "Cody Jiang is a fantastic student in CS-UY-4613!"
|
| 10 |
|
| 11 |
+
# Select pretrained model
|
| 12 |
+
model_names = ['distilbert-base-uncased-finetuned-sst-2-english', 'bert-base-uncased', 'roberta-base', 'Codys Finetuning Language Model']
|
| 13 |
+
model_name = st.selectbox("Select a pretrained model", model_names)
|
| 14 |
|
| 15 |
+
# Load selected model and tokenizer
|
| 16 |
if model_name == 'Codys Finetuning Language Model':
|
| 17 |
+
model_path = './model'
|
| 18 |
else:
|
| 19 |
model_path = model_name
|
| 20 |
tokenizer = transformers.AutoTokenizer.from_pretrained(model_path)
|
|
|
|
| 34 |
inputs = inputs.to(device)
|
| 35 |
outputs = model(**inputs)
|
| 36 |
logits = outputs.logits
|
| 37 |
+
probabilities = torch.sigmoid(logits).detach().cpu().numpy()[0]
|
| 38 |
+
predictions = (probabilities >= 0.5).astype(int)
|
| 39 |
+
result_df = pd.DataFrame({'Text': [text], 'Probability': probabilities, 'Label': toxicity_labels, 'Prediction': predictions})
|
| 40 |
+
st.table(result_df[['Text', 'Prediction', 'Probability']])
|
|
|
|
|
|
|
|
|
|
|
|