Update app.py run the model
Browse files
app.py
CHANGED
@@ -1,42 +1,46 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
#
|
4 |
-
st.
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
|
|
|
|
|
|
|
|
7 |
model_selection = st.sidebar.selectbox(
|
8 |
"Select a model",
|
9 |
options=['alm', 'blm'],
|
10 |
index=0 # Default selection
|
11 |
)
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
anti_entities = st.text_input("Anti Entities", help="Enter anti entities separated by commas")
|
21 |
-
neutral_entities = st.text_input("Neutral Entities", help="Enter neutral entities separated by commas")
|
22 |
|
23 |
-
|
24 |
-
st.header("Aspects")
|
25 |
-
# Free-text inputs for aspects
|
26 |
-
pro_aspects = st.text_input("Pro Aspects", help="Enter pro aspects separated by commas")
|
27 |
-
anti_aspects = st.text_input("Anti Aspects", help="Enter anti aspects separated by commas")
|
28 |
-
neutral_aspects = st.text_input("Neutral Aspects", help="Enter neutral aspects separated by commas")
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
|
|
|
33 |
if generate_button:
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
st.write(f"Neutral Aspects: {neutral_aspects}")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the model and tokenizer once, to avoid reloading them on each user interaction
|
5 |
+
@st.cache(allow_output_mutation=True)
|
6 |
+
def load_model():
|
7 |
+
classifier = pipeline("text-classification", model="tweetpie/toxic-content-classifier")
|
8 |
+
return classifier
|
9 |
|
10 |
+
# Set up the title
|
11 |
+
st.title("Toxic Content Classifier Dashboard")
|
12 |
+
|
13 |
+
# Sidebar setup for configuration
|
14 |
+
st.sidebar.header("Configuration")
|
15 |
model_selection = st.sidebar.selectbox(
|
16 |
"Select a model",
|
17 |
options=['alm', 'blm'],
|
18 |
index=0 # Default selection
|
19 |
)
|
20 |
|
21 |
+
# Sidebar inputs with headers for entities and aspects
|
22 |
+
st.sidebar.header("Entities")
|
23 |
+
pro_entities = st.sidebar.text_input("Pro Entities", help="Enter pro entities separated by commas")
|
24 |
+
anti_entities = st.sidebar.text_input("Anti Entities", help="Enter anti entities separated by commas")
|
25 |
+
neutral_entities = st.sidebar.text_input("Neutral Entities", help="Enter neutral entities separated by commas")
|
26 |
|
27 |
+
st.sidebar.header("Aspects")
|
28 |
+
pro_aspects = st.sidebar.text_input("Pro Aspects", help="Enter pro aspects separated by commas")
|
29 |
+
anti_aspects = st.sidebar.text_input("Anti Aspects", help="Enter anti aspects separated by commas")
|
30 |
+
neutral_aspects = st.sidebar.text_input("Neutral Aspects", help="Enter neutral aspects separated by commas")
|
|
|
|
|
31 |
|
32 |
+
generate_button = st.sidebar.button("Generate")
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# Load the model
|
35 |
+
classifier = load_model()
|
36 |
|
37 |
+
# Process the input text and generate output
|
38 |
if generate_button:
|
39 |
+
with st.spinner('Processing...'):
|
40 |
+
# Call the model with the input text
|
41 |
+
input_text = "I love you"
|
42 |
+
model_output = classifier(input_text)
|
43 |
+
|
44 |
+
# Displaying the input and model's output
|
45 |
+
st.write(f"Input Text: {input_text}")
|
46 |
+
st.write("Model Output:", model_output)
|
|