Commit
·
e8a5261
1
Parent(s):
52bd259
fix session state init
Browse files
app.py
CHANGED
@@ -1,9 +1,16 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from random import choice
|
3 |
from annotated_text import annotated_text
|
4 |
from resources import *
|
5 |
from helpers import *
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
base_model = "xlnet-base-cased"
|
8 |
sentences = load_sentences()
|
9 |
baseline_classifier = load_model(f"Dagobert42/{base_model}-biored-finetuned")
|
@@ -18,19 +25,19 @@ It was tagged by a model which was trained on 200 examples from the original dat
|
|
18 |
It is very possible that there should be some mistakes.
|
19 |
""")
|
20 |
|
21 |
-
txt = sentences[
|
22 |
|
23 |
-
st.write("Example with data augmentation:" if
|
24 |
-
tokens = augmented_classifier(txt) if
|
25 |
|
26 |
annotated_text(annotate_sentence(txt, tokens))
|
27 |
st.write(annotate_sentence(txt, tokens))
|
28 |
|
29 |
st.write("Now try the augmented model. Hopefully it's a bit better :)")
|
30 |
-
|
31 |
|
32 |
st.write("Or load another sentence")
|
33 |
def refresh_example():
|
34 |
-
|
35 |
st.button( ":twisted_rightwards_arrows:", on_click=refresh_example)
|
36 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from streamlit import session_state
|
3 |
from random import choice
|
4 |
from annotated_text import annotated_text
|
5 |
from resources import *
|
6 |
from helpers import *
|
7 |
|
8 |
+
if "counter" not in session_state:
|
9 |
+
session_state.counter = 0
|
10 |
+
|
11 |
+
if "augment" not in session_state:
|
12 |
+
session_state.augment = False
|
13 |
+
|
14 |
base_model = "xlnet-base-cased"
|
15 |
sentences = load_sentences()
|
16 |
baseline_classifier = load_model(f"Dagobert42/{base_model}-biored-finetuned")
|
|
|
25 |
It is very possible that there should be some mistakes.
|
26 |
""")
|
27 |
|
28 |
+
txt = sentences[session_state.counter]
|
29 |
|
30 |
+
st.write("Example with data augmentation:" if session_state.augment else "Example without data augmentation:")
|
31 |
+
tokens = augmented_classifier(txt) if session_state.augment else baseline_classifier(txt)
|
32 |
|
33 |
annotated_text(annotate_sentence(txt, tokens))
|
34 |
st.write(annotate_sentence(txt, tokens))
|
35 |
|
36 |
st.write("Now try the augmented model. Hopefully it's a bit better :)")
|
37 |
+
session_state.augment = st.toggle("augmentations on" if session_state.augment else "augmentations off")
|
38 |
|
39 |
st.write("Or load another sentence")
|
40 |
def refresh_example():
|
41 |
+
session_state.counter += 1
|
42 |
st.button( ":twisted_rightwards_arrows:", on_click=refresh_example)
|
43 |
|