File size: 479 Bytes
ec8e443
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
from transformers import pipeline
import os

# Set your Hugging Face token as an environment variable
# Make sure this token is valid and has the necessary permissions
# or, pass the token directly to the pipeline function
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad") # Replace with your actual token


def answer_question(question, context):
    result = qa_pipeline(question=question, context=context)
    return result['answer']