Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ from deepdoctection.utils.settings import get_type
|
|
17 |
from dd_addons.analyzer.loader import get_loader
|
18 |
from dd_addons.extern.guidance import TOKEN_DEFAULT_INSTRUCTION
|
19 |
from dd_addons.utils.settings import register_llm_token_tag, register_string_categories_from_list
|
20 |
-
from dd_addons.extern.openai import OpenAiLmmTokenClassifier
|
21 |
|
22 |
import gradio as gr
|
23 |
|
@@ -27,6 +27,8 @@ demo = gr.Blocks(css="scrollbar.css")
|
|
27 |
|
28 |
|
29 |
def process_analyzer(openai_api_key, categories_str, instruction_str, img, pdf, max_datapoints):
|
|
|
|
|
30 |
categories_list = categories_str.split(",")
|
31 |
register_string_categories_from_list(categories_list, "custom_token_classes")
|
32 |
custom_token_class = dd.object_types_registry.get("custom_token_classes")
|
@@ -65,7 +67,7 @@ def process_analyzer(openai_api_key, categories_str, instruction_str, img, pdf,
|
|
65 |
json_out[f"page_{idx}"] = dp.get_token()
|
66 |
|
67 |
return [dp.viz(show_cells=False, show_layouts=False, show_tables=False, show_words=True, show_token_class=True, ignore_default_token_class=True)
|
68 |
-
for dp in dpts], json_out
|
69 |
|
70 |
|
71 |
with demo:
|
@@ -93,6 +95,7 @@ with demo:
|
|
93 |
with gr.Box():
|
94 |
gr.Markdown("Enter your OpenAI API Key* ")
|
95 |
user_token = gr.Textbox(value='', placeholder="OpenAI API Key", type="password", show_label=False)
|
|
|
96 |
gr.Markdown("<sup>* Your API key will not be saved. However, it is always recommended to deactivate the"
|
97 |
"API key once it is entered into an unknown source</sup>")
|
98 |
with gr.Column():
|
@@ -100,7 +103,7 @@ with demo:
|
|
100 |
gr.Markdown(
|
101 |
"Enter a list of comma seperated entities. Use a snake case style. Avoid special characters. "
|
102 |
"Best way is to only use `a-z` and `_`")
|
103 |
-
categories = gr.Textbox(value='
|
104 |
with gr.Box():
|
105 |
gr.Markdown("Optional: Enter a prompt for additional guidance. Will use the placeholder as fallback")
|
106 |
instruction = gr.Textbox(value='', placeholder=TOKEN_DEFAULT_INSTRUCTION, show_label=False)
|
@@ -114,6 +117,10 @@ with demo:
|
|
114 |
with gr.Box():
|
115 |
gr.Markdown("<h2><center>Outputs</center></h2>")
|
116 |
with gr.Row():
|
|
|
|
|
|
|
|
|
117 |
with gr.Column():
|
118 |
with gr.Box():
|
119 |
gr.Markdown("<center><strong>JSON</strong></center>")
|
@@ -130,6 +137,6 @@ with demo:
|
|
130 |
html = gr.HTML()
|
131 |
|
132 |
btn.click(fn=process_analyzer, inputs=[user_token, categories, instruction, inputs, inputs_pdf, max_imgs],
|
133 |
-
outputs=[gallery, json])
|
134 |
|
135 |
demo.launch()
|
|
|
17 |
from dd_addons.analyzer.loader import get_loader
|
18 |
from dd_addons.extern.guidance import TOKEN_DEFAULT_INSTRUCTION
|
19 |
from dd_addons.utils.settings import register_llm_token_tag, register_string_categories_from_list
|
20 |
+
from dd_addons.extern.openai import OpenAiLmmTokenClassifier, is_api_key_valid
|
21 |
|
22 |
import gradio as gr
|
23 |
|
|
|
27 |
|
28 |
|
29 |
def process_analyzer(openai_api_key, categories_str, instruction_str, img, pdf, max_datapoints):
|
30 |
+
if not is_api_key_valid(openai_api_key):
|
31 |
+
return [], {}, "You have entered no or an invalid api key. Please enter a valid api key"
|
32 |
categories_list = categories_str.split(",")
|
33 |
register_string_categories_from_list(categories_list, "custom_token_classes")
|
34 |
custom_token_class = dd.object_types_registry.get("custom_token_classes")
|
|
|
67 |
json_out[f"page_{idx}"] = dp.get_token()
|
68 |
|
69 |
return [dp.viz(show_cells=False, show_layouts=False, show_tables=False, show_words=True, show_token_class=True, ignore_default_token_class=True)
|
70 |
+
for dp in dpts], json_out, "No error"
|
71 |
|
72 |
|
73 |
with demo:
|
|
|
95 |
with gr.Box():
|
96 |
gr.Markdown("Enter your OpenAI API Key* ")
|
97 |
user_token = gr.Textbox(value='', placeholder="OpenAI API Key", type="password", show_label=False)
|
98 |
+
|
99 |
gr.Markdown("<sup>* Your API key will not be saved. However, it is always recommended to deactivate the"
|
100 |
"API key once it is entered into an unknown source</sup>")
|
101 |
with gr.Column():
|
|
|
103 |
gr.Markdown(
|
104 |
"Enter a list of comma seperated entities. Use a snake case style. Avoid special characters. "
|
105 |
"Best way is to only use `a-z` and `_`")
|
106 |
+
categories = gr.Textbox(value='', placeholder="mitarbeiter_anzahl", show_label=False)
|
107 |
with gr.Box():
|
108 |
gr.Markdown("Optional: Enter a prompt for additional guidance. Will use the placeholder as fallback")
|
109 |
instruction = gr.Textbox(value='', placeholder=TOKEN_DEFAULT_INSTRUCTION, show_label=False)
|
|
|
117 |
with gr.Box():
|
118 |
gr.Markdown("<h2><center>Outputs</center></h2>")
|
119 |
with gr.Row():
|
120 |
+
with gr.Column():
|
121 |
+
with gr.Box():
|
122 |
+
gr.Markdown("<center><strong>Message</strong></center>")
|
123 |
+
msg = gr.Textbox(value='', placeholder="message", show_label=False)
|
124 |
with gr.Column():
|
125 |
with gr.Box():
|
126 |
gr.Markdown("<center><strong>JSON</strong></center>")
|
|
|
137 |
html = gr.HTML()
|
138 |
|
139 |
btn.click(fn=process_analyzer, inputs=[user_token, categories, instruction, inputs, inputs_pdf, max_imgs],
|
140 |
+
outputs=[gallery, json, msg])
|
141 |
|
142 |
demo.launch()
|