File size: 1,040 Bytes
3c63390
49ea6d4
116a19e
43e821a
 
49ea6d4
d7215ca
49ea6d4
 
 
3c63390
6257cd7
49ea6d4
43e821a
 
6257cd7
 
49ea6d4
6257cd7
49ea6d4
6257cd7
43e821a
6257cd7
49ea6d4
 
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
import streamlit as st
from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering

@st.cache(allow_output_mutation=True)
def load_qa_model():
    model_name = "google/mobilebert-uncased"
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForQuestionAnswering.from_pretrained(model_name)
    qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
    return qa_pipeline

qa = load_qa_model()

st.title("Ask Questions about your Text")
sentence = st.text_area('Please paste your article :', height=30)
question = st.text_input("Questions from this article?")
button = st.button("Get me Answers")
max_seq_length = st.sidebar.slider('Select max sequence length', 50, 500, step=10, value=150)
do_sample = st.sidebar.checkbox("Do sample", value=False)

with st.spinner("Discovering Answers.."):
    if button and sentence:
        answers = qa(question=question, context=sentence)
        st.write("Answer:", answers['answer'])
        st.write("Score:", answers['score'])