vluz commited on
Commit
23ce26c
1 Parent(s): 9cec5b0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -1
README.md CHANGED
@@ -8,7 +8,53 @@ https://www.kaggle.com/competitions/jigsaw-toxic-comment-classification-challeng
8
 
9
  Trained over 20 epoch in a runpod
10
 
11
- Code can be found here:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  <br>
13
  https://github.com/vluz/ToxTest/
14
  <br>
 
8
 
9
  Trained over 20 epoch in a runpod
10
 
11
+
12
+ ```python
13
+ import os
14
+ import pickle
15
+ import streamlit as st
16
+ import tensorflow as tf
17
+ from tensorflow.keras.layers import TextVectorization
18
+
19
+
20
+ @st.cache_resource
21
+ def load_model():
22
+ model = tf.keras.models.load_model(os.path.join("model", "toxmodel.keras"))
23
+ return model
24
+
25
+
26
+ @st.cache_resource
27
+ def load_vectorizer():
28
+ from_disk = pickle.load(open(os.path.join("model", "vectorizer.pkl"), "rb"))
29
+ new_v = TextVectorization.from_config(from_disk['config'])
30
+ new_v.adapt(tf.data.Dataset.from_tensor_slices(["xyz"])) # Keras bug
31
+ new_v.set_weights(from_disk['weights'])
32
+ return new_v
33
+
34
+
35
+ st.title("Toxic Comment Test")
36
+ st.divider()
37
+ model = load_model()
38
+ vectorizer = load_vectorizer()
39
+ input_text = st.text_area("Comment:", "I love you man, but fuck you!", height=150)
40
+ if st.button("Test"):
41
+ with st.spinner("Testing..."):
42
+ inputv = vectorizer([input_text])
43
+ output = model.predict(inputv)
44
+ res = (output > 0.5)
45
+ st.write(["toxic","severe toxic","obscene","threat","insult","identity hate"], res)
46
+ print(output)
47
+ ```
48
+
49
+
50
+ Put `toxmodel.keras` and `vectorizer.pkl` into the `model` dir.
51
+
52
+ Then do do:
53
+ ```
54
+ stramlit run toxtest.py
55
+ ```
56
+
57
+ Full code can be found here:
58
  <br>
59
  https://github.com/vluz/ToxTest/
60
  <br>