Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,20 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import pickle
|
| 3 |
import streamlit as st
|
| 4 |
import tensorflow as tf
|
| 5 |
from tensorflow.keras.layers import TextVectorization
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@st.cache_resource
|
| 9 |
def load_model():
|
| 10 |
model = tf.keras.models.load_model(os.path.join("model", "toxmodel.keras"))
|
|
@@ -34,7 +44,8 @@ if st.button("Test"):
|
|
| 34 |
if input_text == default_prompt:
|
| 35 |
st.write("Expected results from default prompt are positive for 0 and 2")
|
| 36 |
with st.spinner("Testing..."):
|
| 37 |
-
|
|
|
|
| 38 |
output = model.predict(inputv)
|
| 39 |
res = (output > 0.5)
|
| 40 |
st.write(["toxic","severe toxic","obscene","threat","insult","identity hate"], res)
|
|
|
|
| 1 |
import os
|
| 2 |
+
import re
|
| 3 |
import pickle
|
| 4 |
import streamlit as st
|
| 5 |
import tensorflow as tf
|
| 6 |
from tensorflow.keras.layers import TextVectorization
|
| 7 |
|
| 8 |
|
| 9 |
+
def clean_text(text):
|
| 10 |
+
text = re.sub(r'<[^>]+>', '', text)
|
| 11 |
+
text = re.sub(r'http\S+|www\S+|https\S+', '', text)
|
| 12 |
+
text = re.sub(r'[^a-zA-Z\'\s]', ' ', text)
|
| 13 |
+
text = re.sub(r'(\s)([iI][eE]|[eE][gG])(\s)', r' \2 ', text)
|
| 14 |
+
text = " ".join(text.split())
|
| 15 |
+
return text.lower()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
@st.cache_resource
|
| 19 |
def load_model():
|
| 20 |
model = tf.keras.models.load_model(os.path.join("model", "toxmodel.keras"))
|
|
|
|
| 44 |
if input_text == default_prompt:
|
| 45 |
st.write("Expected results from default prompt are positive for 0 and 2")
|
| 46 |
with st.spinner("Testing..."):
|
| 47 |
+
clean_input_text = clean_text(input_text)
|
| 48 |
+
inputv = vectorizer([clean_input_text])
|
| 49 |
output = model.predict(inputv)
|
| 50 |
res = (output > 0.5)
|
| 51 |
st.write(["toxic","severe toxic","obscene","threat","insult","identity hate"], res)
|