Spaces:
Sleeping
Sleeping
File size: 1,114 Bytes
5bfab8c |
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 42 43 44 45 |
from transformers import pipeline
import streamlit as st
# def que():
# question = st.text_input("ASk me a question")
# oracle = pipeline(task= "question-answering",model="deepset/roberta-base-squad2")
# oracle(question="Where do I live?", context="My name is Wolfgang and I live in Berlin")
def question_answering(question, context):
"""Answers a question given a context."""
# Load the question answering model.
qa_model = pipeline("question-answering")
# Prepare the inputs for the model.
inputs = {
"question": question,
"context": context,
}
# Get the answer from the model.
output = qa_model(**inputs)
answer = output["answer_start"]
# Return the answer.
return context[answer : answer + output["answer_length"]]
if __name__ == "__main__":
# Get the question and context.
question = "What is the capital of France?"
context = "The capital of France is Paris."
# Get the answer.
answer = question_answering(question, context)
# Print the answer.
print(answer)
|