Ransaka commited on
Commit
0c2ae87
1 Parent(s): 2d13245

Added hf_token

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -5,8 +5,11 @@ import altair as alt
5
  from transformers import pipeline
6
  from transformers import AutoTokenizer
7
  import warnings
 
8
  warnings.filterwarnings('ignore')
9
 
 
 
10
  # set up altair theme
11
  font = 'NotoSansSinhala.ttf'
12
  font_color = '#858991'
@@ -36,7 +39,7 @@ def get_model_id():
36
  model_list = ["Ransaka/sinhala-bert-small","Ransaka/SinhalaRoberta","keshan/SinhalaBERTo"]
37
  selected_model = st.selectbox("Select Model", model_list)
38
  st.write(f"Selected model: {selected_model}")
39
- tokenizer = AutoTokenizer.from_pretrained(selected_model)
40
  mask_token = tokenizer.mask_token
41
  return selected_model,mask_token
42
 
@@ -95,7 +98,7 @@ if __name__ == "__main__":
95
  if sentence:
96
  prompt = get_prompt(mask_token)
97
  if prompt and st.button("Classify"):
98
- pipe = pipeline("fill-mask", model=model_id)
99
  output = pipe(sentence + prompt, targets=TARGETS, top_k =len(TARGETS))
100
  output = pd.DataFrame(output)
101
  output['score'] = output['score'].apply(lambda x:x/sum(output['score']))
 
5
  from transformers import pipeline
6
  from transformers import AutoTokenizer
7
  import warnings
8
+ import os
9
  warnings.filterwarnings('ignore')
10
 
11
+ hf_token = os.environ['HF_READ']
12
+
13
  # set up altair theme
14
  font = 'NotoSansSinhala.ttf'
15
  font_color = '#858991'
 
39
  model_list = ["Ransaka/sinhala-bert-small","Ransaka/SinhalaRoberta","keshan/SinhalaBERTo"]
40
  selected_model = st.selectbox("Select Model", model_list)
41
  st.write(f"Selected model: {selected_model}")
42
+ tokenizer = AutoTokenizer.from_pretrained(selected_model, token=hf_token)
43
  mask_token = tokenizer.mask_token
44
  return selected_model,mask_token
45
 
 
98
  if sentence:
99
  prompt = get_prompt(mask_token)
100
  if prompt and st.button("Classify"):
101
+ pipe = pipeline("fill-mask", model=model_id, token=hf_token)
102
  output = pipe(sentence + prompt, targets=TARGETS, top_k =len(TARGETS))
103
  output = pd.DataFrame(output)
104
  output['score'] = output['score'].apply(lambda x:x/sum(output['score']))