Spaces:
Sleeping
Sleeping
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'] | |