Spaces:
Sleeping
Sleeping
File size: 1,106 Bytes
7602826 49bdb80 7602826 49bdb80 7602826 49bdb80 | 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 | import streamlit as st
from transformers import pipeline
def main():
# App title and description
st.title("Answering questions from text")
st.write("Upload text, pose questions, get answers")
# Load file
raw_text = load_file()
if raw_text is not None and raw_text != '':
# Display text
with st.expander("See text"):
st.write(raw_text)
# Perform question answering
question_answerer = pipeline('question-answering')
answer = ''
question = st.text_input('Ask a question')
if question != '' and raw_text != '':
answer = question_answerer({
'question': question,
'context': raw_text
})
st.write(answer)
def load_file():
"""Load text from file"""
uploaded_file = st.file_uploader("Upload Files", type=['txt'])
if uploaded_file is not None:
if uploaded_file.type == "text/plain":
raw_text = str(uploaded_file.read(), "utf-8")
return raw_text
if __name__ == "__main__":
main()
sample.txt file |