File size: 666 Bytes
e04dbaf 3617742 e04dbaf 88ee736 e04dbaf b4657e8 c663241 64fedd7 2fd996b 3e6eb3b efc9dcd 502fd5c 3617742 efc9dcd 2fd996b efc9dcd 3617742 64fedd7 3617742 |
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 |
import gradio as gr
from pypdf import PdfReader
from transformers import pipeline
pipe = pipeline("question-answering", model='distilbert-base-uncased-distilled-squad')
def predict(file_obj, question):
docText = ""
reader = PdfReader(file_obj.name)
print(len(reader.pages))
for page in reader.pages:
txt = page.extract_text()
docText += f" {txt}"
qaInput = {
'question': question,
'context': docText
}
print(docText[-10:-1])
return pipe(qaInput)
demo = gr.Interface(
fn=predict,
inputs=[gr.File(file_count="single", file_types=[".pdf"]), "text"],
outputs=["text"]
)
demo.launch() |