Andrei Shadrikov
commited on
Commit
·
e5c702c
1
Parent(s):
3fa8524
themes
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import tempfile
|
|
| 8 |
from transformers import pipeline
|
| 9 |
import subprocess as sp
|
| 10 |
|
|
|
|
| 11 |
FILE_TIMEOUT = 10 ** 3
|
| 12 |
MAX_FILES = 10
|
| 13 |
|
|
@@ -16,6 +17,14 @@ p = pipeline(
|
|
| 16 |
model="impira/layoutlm-document-qa",
|
| 17 |
)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def handle_files(cur_files):
|
| 20 |
cur_time = cur_files[-1][0]
|
| 21 |
deleted_indices = set()
|
|
@@ -73,7 +82,7 @@ def interact_with_pdf(doc, question):
|
|
| 73 |
outputs += p(img, question)
|
| 74 |
return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
|
| 75 |
|
| 76 |
-
|
| 77 |
text_interface = gr.Interface(
|
| 78 |
fn=extract_text,
|
| 79 |
inputs=PDF(label="Загрузить PDF"),
|
|
@@ -106,12 +115,12 @@ tabbed_interface = gr.TabbedInterface(
|
|
| 106 |
[text_interface, pdf_interface, image_interface],
|
| 107 |
title="Взаимодействие с PDF",
|
| 108 |
tab_names=["В текст", "В картинки", "Задай вопрос"],
|
| 109 |
-
# description="Choose a tab to perform the desired task."
|
|
|
|
| 110 |
)
|
| 111 |
'''
|
| 112 |
|
| 113 |
with gr.Blocks() as tabbed_interface:
|
| 114 |
-
out_files = gr.State([])
|
| 115 |
with gr.Tab("В текст"):
|
| 116 |
inp1 = PDF(label="Загрузить PDF")
|
| 117 |
out1 = gr.Textbox(label="Полученный текст")
|
|
@@ -128,5 +137,6 @@ with gr.Blocks() as tabbed_interface:
|
|
| 128 |
out3 = gr.Textbox(label="Возможный ответ")
|
| 129 |
btn3 = gr.Button("Запустить")
|
| 130 |
btn3.click(fn=interact_with_pdf, inputs=[inp3, inp4], outputs=out3)
|
|
|
|
| 131 |
|
| 132 |
tabbed_interface.launch(show_api=False, max_threads=8)
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
import subprocess as sp
|
| 10 |
|
| 11 |
+
out_files = gr.State([])
|
| 12 |
FILE_TIMEOUT = 10 ** 3
|
| 13 |
MAX_FILES = 10
|
| 14 |
|
|
|
|
| 17 |
model="impira/layoutlm-document-qa",
|
| 18 |
)
|
| 19 |
|
| 20 |
+
custom_css = """
|
| 21 |
+
<style>
|
| 22 |
+
button.gradio-pdf-button {
|
| 23 |
+
background-color: #99FF00 !important;
|
| 24 |
+
}
|
| 25 |
+
</style>
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
def handle_files(cur_files):
|
| 29 |
cur_time = cur_files[-1][0]
|
| 30 |
deleted_indices = set()
|
|
|
|
| 82 |
outputs += p(img, question)
|
| 83 |
return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
|
| 84 |
|
| 85 |
+
|
| 86 |
text_interface = gr.Interface(
|
| 87 |
fn=extract_text,
|
| 88 |
inputs=PDF(label="Загрузить PDF"),
|
|
|
|
| 115 |
[text_interface, pdf_interface, image_interface],
|
| 116 |
title="Взаимодействие с PDF",
|
| 117 |
tab_names=["В текст", "В картинки", "Задай вопрос"],
|
| 118 |
+
# description="Choose a tab to perform the desired task.",
|
| 119 |
+
css=custom_css
|
| 120 |
)
|
| 121 |
'''
|
| 122 |
|
| 123 |
with gr.Blocks() as tabbed_interface:
|
|
|
|
| 124 |
with gr.Tab("В текст"):
|
| 125 |
inp1 = PDF(label="Загрузить PDF")
|
| 126 |
out1 = gr.Textbox(label="Полученный текст")
|
|
|
|
| 137 |
out3 = gr.Textbox(label="Возможный ответ")
|
| 138 |
btn3 = gr.Button("Запустить")
|
| 139 |
btn3.click(fn=interact_with_pdf, inputs=[inp3, inp4], outputs=out3)
|
| 140 |
+
'''
|
| 141 |
|
| 142 |
tabbed_interface.launch(show_api=False, max_threads=8)
|