eubinecto commited on
Commit
253de62
1 Parent(s): a361918

[#2] deploying the model with `main_deploy.py`.

Browse files
Files changed (4) hide show
  1. config.yaml +1 -0
  2. idiomify/pipeline.py +2 -2
  3. main_deploy.py +41 -0
  4. requirements.txt +3 -1
config.yaml CHANGED
@@ -4,6 +4,7 @@ idiomifier:
4
  bart: facebook/bart-base
5
  lr: 0.0001
6
  literal2idiomatic_ver: d-1-2
 
7
  max_epochs: 2
8
  batch_size: 40
9
  shuffle: true
 
4
  bart: facebook/bart-base
5
  lr: 0.0001
6
  literal2idiomatic_ver: d-1-2
7
+ idioms_ver: d-1-2
8
  max_epochs: 2
9
  batch_size: 40
10
  shuffle: true
idiomify/pipeline.py CHANGED
@@ -1,7 +1,7 @@
1
  from typing import List
2
  from transformers import BartTokenizer
3
- from builders import SourcesBuilder
4
- from models import Idiomifier
5
 
6
 
7
  class Pipeline:
 
1
  from typing import List
2
  from transformers import BartTokenizer
3
+ from idiomify.builders import SourcesBuilder
4
+ from idiomify.models import Idiomifier
5
 
6
 
7
  class Pipeline:
main_deploy.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ we deploy the pipeline via streamlit.
3
+ """
4
+ from typing import Tuple, List
5
+ import streamlit as st
6
+ from transformers import BartTokenizer
7
+ from idiomify.fetchers import fetch_config, fetch_idiomifier, fetch_idioms
8
+ from idiomify.pipeline import Pipeline
9
+ from idiomify.models import Idiomifier
10
+
11
+
12
+ @st.cache(allow_output_mutation=True)
13
+ def fetch() -> Tuple[Idiomifier, BartTokenizer, List[str]]:
14
+ config = fetch_config()['idiomifier']
15
+ model = fetch_idiomifier(config['ver'])
16
+ idioms = fetch_idioms(config['idioms_ver'])
17
+ tokenizer = BartTokenizer.from_pretrained(config['bart'])
18
+ return model, tokenizer, idioms
19
+
20
+
21
+ def main():
22
+ # fetch a pre-trained model
23
+ model, tokenizer, idioms = fetch()
24
+ pipeline = Pipeline(model, tokenizer)
25
+ st.title("Idiomify Demo")
26
+ text = st.text_area("Type sentences here",
27
+ value="Just remember there will always be a hope even when things look black")
28
+ with st.sidebar:
29
+ st.subheader("Supported idioms")
30
+ st.write(" / ".join(idioms))
31
+
32
+ if st.button(label="Idiomify"):
33
+ with st.spinner("Please wait..."):
34
+ sents = [sent for sent in text.split(".") if sent]
35
+ sents = pipeline(sents, max_length=200)
36
+ # highlight the rule & honorifics that were applied
37
+ st.write(". ".join(sents))
38
+
39
+
40
+ if __name__ == '__main__':
41
+ main()
requirements.txt CHANGED
@@ -2,4 +2,6 @@ pytorch-lightning==1.5.10
2
  transformers==4.16.2
3
  wandb==0.12.10
4
  scikit-learn==1.0.2
5
- pandas==1.4.1
 
 
 
2
  transformers==4.16.2
3
  wandb==0.12.10
4
  scikit-learn==1.0.2
5
+ pandas==1.4.1
6
+ streamlit==1.7.0
7
+ watchdog==2.1.6