Habieb143 commited on
Commit
49ea6d4
1 Parent(s): 6257cd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import streamlit as st
2
- from transformers import pipeline, AutoModelForQuestionAnswering, AutoTokenizer
3
 
4
  @st.cache(allow_output_mutation=True)
5
  def load_qa_model():
6
- model_name = "mrm8488/mobilebert-uncased-finetuned-squadv2"
7
- model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
- qa = pipeline("question-answering", model=model, tokenizer=tokenizer)
10
- return qa
 
11
 
12
  qa = load_qa_model()
 
13
  st.title("Ask Questions about your Text")
14
  sentence = st.text_area('Please paste your article :', height=30)
15
  question = st.text_input("Questions from this article?")
16
  button = st.button("Get me Answers")
17
- max = st.sidebar.slider('Select max', 50, 500, step=10, value=150)
18
- min = st.sidebar.slider('Select min', 10, 450, step=10, value=50)
19
  do_sample = st.sidebar.checkbox("Do sample", value=False)
 
20
  with st.spinner("Discovering Answers.."):
21
  if button and sentence:
22
  answers = qa(question=question, context=sentence)
23
- st.write(answers['answer'])
 
 
1
  import streamlit as st
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
3
 
4
  @st.cache(allow_output_mutation=True)
5
  def load_qa_model():
6
+ model_name = "google/mobilebert-uncased"
 
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
9
+ qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
10
+ return qa_pipeline
11
 
12
  qa = load_qa_model()
13
+
14
  st.title("Ask Questions about your Text")
15
  sentence = st.text_area('Please paste your article :', height=30)
16
  question = st.text_input("Questions from this article?")
17
  button = st.button("Get me Answers")
18
+ max_seq_length = st.sidebar.slider('Select max sequence length', 50, 500, step=10, value=150)
 
19
  do_sample = st.sidebar.checkbox("Do sample", value=False)
20
+
21
  with st.spinner("Discovering Answers.."):
22
  if button and sentence:
23
  answers = qa(question=question, context=sentence)
24
+ st.write("Answer:", answers['answer'])
25
+ st.write("Score:", answers['score'])