import streamlit as st from transformers import pipeline unmasker = pipeline('fill-mask', model='dsfsi/zabantu-nso-ven-170m') def fill_mask(sentences): results = {} for sentence in sentences: unmasked = unmasker(sentence) results[sentence] = unmasked return results def replace_mask(sentence, predicted_word): return sentence.replace("", predicted_word) st.title("Fill Mask | Zabantu-nso-ven-170m) st.write(f"") col1, col2 = st.columns(2) with col1: sample_sentences = [ "Vhana vhane vha kha ḓi bva u bebwa vha kha khombo ya u nga Listeriosis" ] text_input = st.text_area( "Enter sentences with token (one per line):", "\n".join(sample_sentences) ) input_sentences = text_input.split(",") if st.button("Submit"): result = fill_mask(input_sentences) with col2: if 'result' in locals(): if result: for sentence, predictions in result.items(): for prediction in predictions: predicted_word = prediction['token_str'] score = prediction['score'] * 100 st.markdown(f"""
{predicted_word}
{score:.2f}%
""", unsafe_allow_html=True) if 'result' in locals(): if result: for sentence, predictions in result.items(): predicted_word = predictions[0]['token_str'] full_sentence = replace_mask(sentence, predicted_word) st.write(f"**Sentence:** {full_sentence }") css = """ """ st.markdown(css, unsafe_allow_html=True)