mbahrami's picture
Update app.py
fa97b6f
raw
history blame
909 Bytes
import streamlit as st
from transformers import pipeline
@st.cache(allow_output_mutation=True)
def get_model(model):
return pipeline("fill-mask", model=model, top_k=100)
history_keyword_text = st.text_input("Enter users's history keywords (optional, i.e., 'Gates')", value="Gates")
text = st.text_input("Enter a text for auto completion...", value='Where is Bill')
model = st.selectbox("choose a model", ["roberta-base", "bert-base-uncased", "gpt2", "t5"])
data_load_state = st.text('Loading model...')
nlp = get_model(model)
if text:
data_load_state = st.text('Inference to model...')
result = nlp(text+' '+nlp.tokenizer.mask_token)
data_load_state.text('')
for index, r in enumerate(result):
print(1)
if r['token_str'].lower().strip() in history_keyword_text.lower().strip():
st.caption(r)
result[index]['score']*=0.10
st.table(result)