File size: 1,311 Bytes
3d51456 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import streamlit as st
from transformers import pipeline
# Page config
st.set_page_config(page_title="Blank Space Filling Model", page_icon="📝", layout="centered")
st.title("📝 Blank Space Filling Model")
st.write("Type a sentence with a blank using **____** or **[MASK]**.")
# Load Hugging Face model
@st.cache_resource
def load_model():
return pipeline("fill-mask", model="bert-base-uncased")
fill_mask = load_model()
# Input box
user_input = st.text_input(
"Enter your sentence:",
"India is a ____ country."
)
# Prediction button
if st.button("Fill Blank"):
sentence = user_input.replace("____", "[MASK]")
if "[MASK]" not in sentence:
st.error("Please include a blank like ____ or [MASK].")
else:
with st.spinner("Predicting..."):
results = fill_mask(sentence)
st.success("Prediction completed!")
st.subheader("Top Predictions")
for i, result in enumerate(results[:5], start=1):
word = result["token_str"].strip()
sentence_output = result["sequence"]
confidence = round(result["score"] * 100, 2)
st.write(f"### {i}. {word}")
st.write(f"**Sentence:** {sentence_output}")
st.write(f"**Confidence:** {confidence}%")
st.markdown("---") |