Spaces:
Sleeping
Sleeping
File size: 861 Bytes
adf29ba |
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 |
import gradio as gr
from transformers import pipeline
# Initialize the question-answering pipeline
qa_pipeline = pipeline("question-answering")
def answer_question(context, question):
result = qa_pipeline(question=question, context=context)
return result['answer']
def process(context_file, question):
# Read the context from the uploaded file
with open(context_file.name, 'r') as file:
context = file.read()
answer = answer_question(context, question)
return answer
# Gradio interface
demo = gr.Interface(
fn=process,
inputs=[gr.File(label="Upload Context File"), gr.Textbox(label="Question")],
outputs=[gr.Textbox(label="Answer")],
title="Question Answering",
description="Upload a file with context and ask a question. The answer will be displayed."
)
if __name__ == "__main__":
demo.launch()
|