aumkar commited on
Commit
31b5b58
β€’
1 Parent(s): c57d22c

added code

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import fitz # PyMuPDF
3
+ from transformers import pipeline
4
+
5
+ # Load the Hugging Face question-answering pipeline
6
+ qa_pipeline = pipeline("question-answering")
7
+
8
+ def answer_question(pdf_file, question):
9
+ # Read the PDF file
10
+ doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
11
+ text = ""
12
+ for page in doc:
13
+ text += page.get_text()
14
+
15
+ # Use the QA model to answer the question
16
+ answer = qa_pipeline(question=question, context=text)
17
+ return answer['answer']
18
+
19
+ # Define the Gradio interface
20
+ interface = gr.Interface(
21
+ fn=answer_question,
22
+ inputs=[gr.inputs.File(type="pdf"), gr.inputs.Textbox(lines=2, placeholder="Type your question here...")],
23
+ outputs="text",
24
+ title="PDF Question Answering",
25
+ description="Upload a PDF document and ask a question based on its content."
26
+ )
27
+
28
+ interface.launch()