Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline,
|
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=
|
14 |
-
tokenizer=
|
15 |
)
|
16 |
|
17 |
-
def generate_answer(question,
|
18 |
-
|
19 |
-
result
|
20 |
-
return result['answer']
|
21 |
|
22 |
st.title('Question Answering Model')
|
23 |
question = st.text_input('Enter your question:')
|
24 |
-
|
25 |
|
26 |
if st.button('Generate Answer'):
|
27 |
-
answer = generate_answer(question,
|
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)
|