Andrei Shadrikov
commited on
Commit
·
2d5d236
1
Parent(s):
6095336
fix
Browse files
app.py
CHANGED
|
@@ -65,8 +65,8 @@ def process_pdf(pdf_file, cur_files):
|
|
| 65 |
|
| 66 |
return str(zip_output), cur_files
|
| 67 |
|
| 68 |
-
|
| 69 |
-
def
|
| 70 |
with tempfile.TemporaryDirectory() as path:
|
| 71 |
images = convert_from_path(doc, output_folder=path)
|
| 72 |
outputs = []
|
|
@@ -74,6 +74,7 @@ def process_image_and_text(doc, text_query):
|
|
| 74 |
outputs += p(img, question)
|
| 75 |
return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
|
| 76 |
|
|
|
|
| 77 |
text_interface = gr.Interface(
|
| 78 |
fn=extract_text,
|
| 79 |
inputs=PDF(label="Upload PDF"),
|
|
@@ -91,12 +92,12 @@ pdf_interface = gr.Interface(
|
|
| 91 |
)
|
| 92 |
|
| 93 |
image_interface = gr.Interface(
|
| 94 |
-
fn=
|
| 95 |
inputs=[
|
| 96 |
PDF(label="Upload PDF"),
|
| 97 |
gr.Textbox(label="Text Query")
|
| 98 |
],
|
| 99 |
-
outputs=gr.Textbox(label="Possible
|
| 100 |
title="Ask Your PDF",
|
| 101 |
description="Searches for text in the uploaded image based on the provided query."
|
| 102 |
)
|
|
|
|
| 65 |
|
| 66 |
return str(zip_output), cur_files
|
| 67 |
|
| 68 |
+
|
| 69 |
+
def interact_with_pdf(doc, question):
|
| 70 |
with tempfile.TemporaryDirectory() as path:
|
| 71 |
images = convert_from_path(doc, output_folder=path)
|
| 72 |
outputs = []
|
|
|
|
| 74 |
outputs += p(img, question)
|
| 75 |
return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
|
| 76 |
|
| 77 |
+
|
| 78 |
text_interface = gr.Interface(
|
| 79 |
fn=extract_text,
|
| 80 |
inputs=PDF(label="Upload PDF"),
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
image_interface = gr.Interface(
|
| 95 |
+
fn=interact_with_pdf,
|
| 96 |
inputs=[
|
| 97 |
PDF(label="Upload PDF"),
|
| 98 |
gr.Textbox(label="Text Query")
|
| 99 |
],
|
| 100 |
+
outputs=gr.Textbox(label="Possible Answer"),
|
| 101 |
title="Ask Your PDF",
|
| 102 |
description="Searches for text in the uploaded image based on the provided query."
|
| 103 |
)
|