Dagobert42 commited on
Commit
52bd259
·
1 Parent(s): d026301

try to make variables stateful

Browse files
Files changed (2) hide show
  1. app.py +10 -11
  2. resources.py +2 -6
app.py CHANGED
@@ -5,7 +5,6 @@ from resources import *
5
  from helpers import *
6
 
7
  base_model = "xlnet-base-cased"
8
- session = load_variables()
9
  sentences = load_sentences()
10
  baseline_classifier = load_model(f"Dagobert42/{base_model}-biored-finetuned")
11
  augmented_classifier = load_model(f"Dagobert42/{base_model}-biored-augmented")
@@ -13,25 +12,25 @@ augmented_classifier = load_model(f"Dagobert42/{base_model}-biored-augmented")
13
  st.title("Semantic Frame Augmentation")
14
  st.subheader("Analysing challenging domains with only a handful of examples")
15
 
16
- st.write(f"""This space uses models based on [xlnet](https://huggingface.co/xlnet-base-cased) to identify medical entities in a text.
17
  The following is a random sentence from [bigbio/biored](https://huggingface.co/datasets/bigbio/biored).
18
  It was tagged by a model which was trained on 200 examples from the original dataset.
19
  It is very possible that there should be some mistakes.
20
  """)
21
 
22
- txt = sentences[session["counter"]]
23
- if session["augment"]:
24
- st.write("Results on original biored data:")
25
- tokens = augmented_classifier(txt)
26
- else:
27
- st.write("Results with data augmentation:")
28
- tokens = baseline_classifier(txt)
29
 
30
  annotated_text(annotate_sentence(txt, tokens))
 
31
 
32
  st.write("Now try the augmented model. Hopefully it's a bit better :)")
33
- session["augment"] = st.toggle("augmentations on" if session["augment"] else "augmentations off")
34
 
35
  st.write("Or load another sentence")
36
- st.button( ":twisted_rightwards_arrows:", on_click=lambda: session.setdefault("counter", 0) + 1)
 
 
37
 
 
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")
10
  augmented_classifier = load_model(f"Dagobert42/{base_model}-biored-augmented")
 
12
  st.title("Semantic Frame Augmentation")
13
  st.subheader("Analysing challenging domains with only a handful of examples")
14
 
15
+ st.write(f"""This space uses models based on [XLNet](https://huggingface.co/xlnet-base-cased) to identify medical entities in a text.
16
  The following is a random sentence from [bigbio/biored](https://huggingface.co/datasets/bigbio/biored).
17
  It was tagged by a model which was trained on 200 examples from the original dataset.
18
  It is very possible that there should be some mistakes.
19
  """)
20
 
21
+ txt = sentences[st.session_state.counter]
22
+
23
+ st.write("Example with data augmentation:" if st.session_state.augment else "Example without data augmentation:")
24
+ tokens = augmented_classifier(txt) if st.session_state.augment else baseline_classifier(txt)
 
 
 
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
+ st.session_state.augment = st.toggle("augmentations on" if st.session_state.augment else "augmentations off")
31
 
32
  st.write("Or load another sentence")
33
+ def refresh_example():
34
+ st.session_state.counter += 1
35
+ st.button( ":twisted_rightwards_arrows:", on_click=refresh_example)
36
 
resources.py CHANGED
@@ -3,12 +3,8 @@ import torch
3
  import streamlit as st
4
  from random import shuffle
5
 
6
- @st.cache_data
7
- def load_variables():
8
- return {
9
- "counter" : 0,
10
- "augment" : False
11
- }
12
 
13
  @st.cache_data
14
  def load_sentences():
 
3
  import streamlit as st
4
  from random import shuffle
5
 
6
+ st.session_state.counter = 0
7
+ st.session_state.augment = False
 
 
 
 
8
 
9
  @st.cache_data
10
  def load_sentences():