Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!pip install transformers
|
| 2 |
+
!pip install streamlit
|
| 3 |
+
!pip install torch
|
| 4 |
+
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
# Title for the app
|
| 9 |
+
st.title('Fill in the Blank Bot')
|
| 10 |
+
|
| 11 |
+
# Load the fill-mask pipeline
|
| 12 |
+
fill_mask = pipeline('fill-mask')
|
| 13 |
+
|
| 14 |
+
# Text area for the user input
|
| 15 |
+
user_input = st.text_area("Enter a sentence with a <mask> in place of the missing word")
|
| 16 |
+
|
| 17 |
+
# Button to trigger the fill-mask function
|
| 18 |
+
if st.button('Fill the Blank'):
|
| 19 |
+
# Predict the missing words
|
| 20 |
+
results = fill_mask(user_input)
|
| 21 |
+
|
| 22 |
+
# Display the top 5 predictions
|
| 23 |
+
st.write("Top predictions:")
|
| 24 |
+
for result in results:
|
| 25 |
+
st.write(f"Prediction: {result['token_str']}; Confidence: {round(result['score'], 4)}")
|