ankitdwivedi31 commited on
Commit
dc81829
1 Parent(s): ecc3e34

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a pipeline as a high-level helper
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from PyPDF2 import PdfReader
6
+
7
+ # model_path= "C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Model/models--deepset--roberta-base-squad2/snapshots/cbf50ba81465d4d8676b8bab348e31835147541b"
8
+
9
+ # question_answer = pipeline("question-answering", model=model_path)
10
+ question_answer = pipeline("question-answering", model="deepset/roberta-base-squad2")
11
+
12
+ # context = """Mark Elliot Zuckerberg ( born May 14, 1984) is an American businessman. He co-founded the social media service Facebook, along with his Harvard roommates in 2004, and its parent company Meta Platforms (formerly Facebook, Inc.), of which he is chairman, chief executive officer and controlling shareholder"""
13
+
14
+ # question = "Who is the founder of Facebook?"
15
+
16
+
17
+
18
+ def read_pdf(file_path):
19
+ with open(file_path, 'rb') as file:
20
+ pdf_reader = PdfReader(file)
21
+ num_pages = len(pdf_reader.pages)
22
+ content = ''
23
+ for page_num in range(num_pages):
24
+ page = pdf_reader.pages[page_num]
25
+ content += page.extract_text()
26
+ return content
27
+
28
+
29
+ def get_answer(file, question):
30
+ context = read_pdf(file)
31
+ answer = question_answer(question=question, context=context)
32
+ return answer['answer']
33
+
34
+ gr.close_all()
35
+
36
+ demo = gr.Interface(fn=get_answer,
37
+ inputs=[gr.File(label="Upload your File") ,gr.Textbox(label="Input the question",lines = 2)],
38
+ outputs=[gr.Textbox(label="Here is the answer",lines = 10)],
39
+ title="Project 5: Query your PDF",
40
+ description="""This app will be used for QnA.""")
41
+ demo.launch()