Spaces:
Sleeping
Sleeping
File size: 969 Bytes
c92c4a2 | 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 | import gradio as gr
from transformers import pipeline
# Load pretrained BERT QA model
qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
# Define QA function
def answer_question(context, question):
if not context.strip() or not question.strip():
return "Please provide both context and question."
result = qa_pipeline(question=question, context=context)
return result["answer"]
# Gradio interface
interface = gr.Interface(
fn=answer_question,
inputs=[
gr.Textbox(label="Paragraph (Context)", lines=10, placeholder="Enter a paragraph about Lenin..."),
gr.Textbox(label="Question", placeholder="Who was Lenin?")
],
outputs=gr.Textbox(label="Answer"),
title="BERT Question Answering",
description="Ask a question based on a custom paragraph using a BERT-based QA model.",
)
if __name__ == "__main__":
interface.launch()
|