ErikDaska commited on
Commit
3fc0fa8
·
verified ·
1 Parent(s): 9aee907

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +40 -1
src/streamlit_app.py CHANGED
@@ -16,6 +16,10 @@ def instantiate_roberta(top_k : int, text : str) -> dict:
16
  pipe = pipeline("fill-mask", model="Iscte-Sintra/RoBERTa-Kriolu", tokenizer="Iscte-Sintra/RoBERTa-Kriolu", token=token)
17
  return pipe(text, top_k=top_k)
18
 
 
 
 
 
19
 
20
  def build_gpt2_page():
21
  try:
@@ -66,13 +70,48 @@ def build_roberta_page():
66
  else:
67
  predicted_text = st.text_input("Predicted Token", disabled=True)
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Your dictionary of models
70
- model_dict = {'RoBERTa': 1, 'GPT-2': 2}
71
 
72
  # Always appears at the top of the sidebar
73
  selected_model = st.sidebar.selectbox("Architecture", list(model_dict.keys()))
74
 
75
  if model_dict[selected_model] == 1:
76
  build_roberta_page()
 
 
77
  else:
78
  build_gpt2_page()
 
16
  pipe = pipeline("fill-mask", model="Iscte-Sintra/RoBERTa-Kriolu", tokenizer="Iscte-Sintra/RoBERTa-Kriolu", token=token)
17
  return pipe(text, top_k=top_k)
18
 
19
+ def instatiate_albertina(top_k : int, text : str) -> dict:
20
+ pipe = pipeline("fill-mask", model="Iscte-Sintra/Albertina-Kriolu", tokenizer="Iscte-Sintra/Albertina-Kriolu", token=token)
21
+ return pipe(text, top_k=top_k)
22
+
23
 
24
  def build_gpt2_page():
25
  try:
 
70
  else:
71
  predicted_text = st.text_input("Predicted Token", disabled=True)
72
 
73
+ def build_albertina_page():
74
+ st.title("Albertina : Encoder")
75
+
76
+ top_k = st.sidebar.number_input('Number of predictions to return', min_value=1, max_value=5, value=1, step=1)
77
+
78
+ st.write("Enter a sentence with a **<mask>** token, and the model will predict the missing word.")
79
+
80
+ results = None
81
+
82
+ col1, col2 = st.columns(2)
83
+
84
+ with col1:
85
+ st.subheader("Input")
86
+ input_text = st.text_input("Input Sentence", "Katxor sta trás di <mask>.")
87
+
88
+ submit = st.button("Submit")
89
+ try:
90
+ if submit and input_text:
91
+ results = instantiate_roberta(top_k, input_text)
92
+ except Exception as e:
93
+ st.warning('There must be a special token "<mask>" in sentence!', icon="⚠️")
94
+ st.warning(e)
95
+
96
+ with col2:
97
+ st.subheader("Prediction")
98
+ if results:
99
+ predicted_text = st.text_input("Predicted Token", value=results[0]['sequence'], disabled=True)
100
+ for result in results:
101
+ st.write(f"**Prediction**: {result['token_str']} | **Confidence**: {round(result['score'], 4)}")
102
+ else:
103
+ predicted_text = st.text_input("Predicted Token", disabled=True)
104
+
105
+
106
  # Your dictionary of models
107
+ model_dict = {'RoBERTa': 1,'Albertina':2 ,'GPT-2': 3}
108
 
109
  # Always appears at the top of the sidebar
110
  selected_model = st.sidebar.selectbox("Architecture", list(model_dict.keys()))
111
 
112
  if model_dict[selected_model] == 1:
113
  build_roberta_page()
114
+ elif model_dict[selected_model] == 2:
115
+ build_albertina_page()
116
  else:
117
  build_gpt2_page()