Isanka commited on
Commit
893c729
1 Parent(s): be5ff90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -5,7 +5,7 @@ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
5
  # Function to extract text from PDF
6
  def extract_text_from_pdf(pdf_path):
7
  text = ""
8
- document = fitz.open(pdf_path)
9
  for page_num in range(len(document)):
10
  page = document.load_page(page_num)
11
  text += page.get_text()
@@ -22,7 +22,7 @@ qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
22
  # Function to answer questions based on the PDF content
23
  def answer_question(pdf_file, question):
24
  # Extract text from the uploaded PDF file
25
- content = extract_text_from_pdf(pdf_file.name)
26
  # Get the answer using the question-answering pipeline
27
  result = qa_pipeline(question=question, context=content)
28
  return result['answer']
@@ -30,7 +30,7 @@ def answer_question(pdf_file, question):
30
  # Define the Gradio interface
31
  iface = gr.Interface(
32
  fn=answer_question,
33
- inputs=[gr.inputs.File(file_count="single", type="file"), gr.inputs.Textbox(lines=2, placeholder="Ask a question...")],
34
  outputs="text",
35
  title="DistilBERT Question Answering",
36
  description="Upload a PDF and ask questions based on the content of the PDF."
 
5
  # Function to extract text from PDF
6
  def extract_text_from_pdf(pdf_path):
7
  text = ""
8
+ document = fitz.open(pdf_path.name)
9
  for page_num in range(len(document)):
10
  page = document.load_page(page_num)
11
  text += page.get_text()
 
22
  # Function to answer questions based on the PDF content
23
  def answer_question(pdf_file, question):
24
  # Extract text from the uploaded PDF file
25
+ content = extract_text_from_pdf(pdf_file)
26
  # Get the answer using the question-answering pipeline
27
  result = qa_pipeline(question=question, context=content)
28
  return result['answer']
 
30
  # Define the Gradio interface
31
  iface = gr.Interface(
32
  fn=answer_question,
33
+ inputs=[gr.File(label="PDF File", file_types=[".pdf"]), gr.Textbox(lines=2, placeholder="Ask a question...")],
34
  outputs="text",
35
  title="DistilBERT Question Answering",
36
  description="Upload a PDF and ask questions based on the content of the PDF."