Spaces:
Runtime error
Runtime error
Commit
·
e3903e3
1
Parent(s):
f597a83
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,15 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import transformers
|
4 |
import torch
|
|
|
|
|
5 |
|
6 |
# Load the pre-trained BERT model and tokenizer
|
7 |
tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-uncased')
|
8 |
model = transformers.BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=6)
|
9 |
|
10 |
# Set up the Streamlit app
|
|
|
11 |
st.title('Toxicity Classification App')
|
12 |
|
13 |
# Create a text input for the user to enter their text
|
@@ -57,3 +60,13 @@ if st.button('Classify'):
|
|
57 |
|
58 |
# Display the persistent DataFrame
|
59 |
st.write('Classification Results:', st.session_state.get('results', pd.DataFrame()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import transformers
|
4 |
import torch
|
5 |
+
import seaborn as sns
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
|
8 |
# Load the pre-trained BERT model and tokenizer
|
9 |
tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-uncased')
|
10 |
model = transformers.BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=6)
|
11 |
|
12 |
# Set up the Streamlit app
|
13 |
+
st.set_page_config(layout="wide")
|
14 |
st.title('Toxicity Classification App')
|
15 |
|
16 |
# Create a text input for the user to enter their text
|
|
|
60 |
|
61 |
# Display the persistent DataFrame
|
62 |
st.write('Classification Results:', st.session_state.get('results', pd.DataFrame()))
|
63 |
+
|
64 |
+
# Plot the distribution of probabilities for each category
|
65 |
+
if len(st.session_state.get('results', pd.DataFrame())) > 0:
|
66 |
+
df = st.session_state['results']
|
67 |
+
fig, axes = plt.subplots(ncols=2, figsize=(12, 6))
|
68 |
+
sns.histplot(data=df, x='Toxic', kde=True, ax=axes[0])
|
69 |
+
axes[0].set_title('Toxic Probability Distribution')
|
70 |
+
sns.histplot(data=df, x='Severe Toxic', kde=True, ax=axes[1])
|
71 |
+
axes[1].set_title('Severe Toxic Probability Distribution')
|
72 |
+
st.pyplot(fig)
|