aumkar's picture
added code
31b5b58
raw
history blame
No virus
852 Bytes
import gradio as gr
import fitz # PyMuPDF
from transformers import pipeline
# Load the Hugging Face question-answering pipeline
qa_pipeline = pipeline("question-answering")
def answer_question(pdf_file, question):
# Read the PDF file
doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
text = ""
for page in doc:
text += page.get_text()
# Use the QA model to answer the question
answer = qa_pipeline(question=question, context=text)
return answer['answer']
# Define the Gradio interface
interface = gr.Interface(
fn=answer_question,
inputs=[gr.inputs.File(type="pdf"), gr.inputs.Textbox(lines=2, placeholder="Type your question here...")],
outputs="text",
title="PDF Question Answering",
description="Upload a PDF document and ask a question based on its content."
)
interface.launch()