Spaces:
Build error
Build error
File size: 816 Bytes
36bf9cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from transformers import pipeline
# Initialize the DistilBERT QA model
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
def generate_answer(question):
# The context can be a static text or dynamic content
context = """
Bill Gates is a co-founder of Microsoft, one of the largest software companies in the world.
He is an entrepreneur, software developer, and philanthropist, known for his role in the development of personal computing.
Gates also played a significant role in shaping the tech industry and later focused on philanthropy through the Bill and Melinda Gates Foundation.
"""
# Use the model to extract the answer from the context
result = qa_pipeline(question=question, context=context)
return result['answer']
|