nxmwxm commited on
Commit
d1be659
·
verified ·
1 Parent(s): 889b6e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,28 +1,27 @@
1
  import streamlit as st
2
- from transformers import pipeline, T5Tokenizer, T5ForConditionalGeneration
3
-
4
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
 
6
  model_repo_path = 'nxmwxm/correct_answer'
7
 
8
-
 
 
9
 
10
  # Load the pipeline with your model and tokenizer
11
  qa_pipeline = pipeline(
12
  'question-answering',
13
- model=model_repo_path,
14
- tokenizer=model_repo_path
15
  )
16
 
17
- def generate_answer(question, distractors):
18
- input_text = f"Question: {question} Distractors: {' '.join(distractors)}"
19
- result = qa_pipeline(question=input_text, context=input_text)
20
- return result['answer']
21
 
22
  st.title('Question Answering Model')
23
  question = st.text_input('Enter your question:')
24
- distractors = st.text_input('Enter distractors (comma separated):').split(',')
25
 
26
  if st.button('Generate Answer'):
27
- answer = generate_answer(question, distractors)
28
  st.write('Answer:', answer)
 
1
  import streamlit as st
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
 
 
3
 
4
  model_repo_path = 'nxmwxm/correct_answer'
5
 
6
+ # Load the tokenizer and model
7
+ tokenizer = AutoTokenizer.from_pretrained(model_repo_path)
8
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_repo_path)
9
 
10
  # Load the pipeline with your model and tokenizer
11
  qa_pipeline = pipeline(
12
  'question-answering',
13
+ model=model,
14
+ tokenizer=tokenizer
15
  )
16
 
17
+ def generate_answer(question, context):
18
+ result = qa_pipeline(question=question, context=context)
19
+ return result.get('answer', 'No answer found')
 
20
 
21
  st.title('Question Answering Model')
22
  question = st.text_input('Enter your question:')
23
+ context = st.text_area('Enter context for the question:')
24
 
25
  if st.button('Generate Answer'):
26
+ answer = generate_answer(question, context)
27
  st.write('Answer:', answer)