Spaces:
Runtime error
Runtime error
A-baoYang
commited on
Commit
•
9fbf2b6
1
Parent(s):
c347c10
Add cat report explanation UI & revise base system prompt
Browse files- api_calls.py +7 -0
- app.py +63 -1
api_calls.py
CHANGED
@@ -36,6 +36,13 @@ def api_qa_waterfee(query, filtered_data):
|
|
36 |
}
|
37 |
return call_api_stream(api_path, api_params)
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def api_ocr(image_filepath, model_provider):
|
40 |
api_path = "ocr"
|
41 |
api_params = {
|
|
|
36 |
}
|
37 |
return call_api_stream(api_path, api_params)
|
38 |
|
39 |
+
def api_qa_cat_report(filtered_data):
|
40 |
+
api_path = "qa/catreportexplain"
|
41 |
+
api_params = {
|
42 |
+
"filtered_data": filtered_data,
|
43 |
+
}
|
44 |
+
return call_api_stream(api_path, api_params)
|
45 |
+
|
46 |
def api_ocr(image_filepath, model_provider):
|
47 |
api_path = "ocr"
|
48 |
api_params = {
|
app.py
CHANGED
@@ -9,6 +9,11 @@ from api_calls import *
|
|
9 |
|
10 |
ROOT_DIR = Path(__file__).resolve().parents[0]
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def preview_uploaded_file(file_paths):
|
14 |
if file_paths:
|
@@ -72,6 +77,13 @@ def bot(query, history, data_array, file_paths, qa_prompt_tmpl, checkbox_replace
|
|
72 |
# full_anwser += character
|
73 |
# yield full_anwser
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
def draw_cat_pain_assessment_result(user_input_image):
|
76 |
if user_input_image:
|
77 |
json_result = api_model_cat_pain_assessment(user_input_image)
|
@@ -122,6 +134,7 @@ a {color: rgb(255, 206, 10) !important}
|
|
122 |
"""
|
123 |
with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green")) as demo:
|
124 |
gr.HTML("<h1>GlobalModelAI AI Product Test</h1><p>Made by `GlobalModelAI Abao`</p>", elem_id="center")
|
|
|
125 |
with gr.Tab("OCR + Text2SQL"):
|
126 |
with gr.Row():
|
127 |
with gr.Column():
|
@@ -138,7 +151,6 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green")) as demo
|
|
138 |
[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-esg_report_table3.png"]],
|
139 |
[[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-medical_thesis_table.png"],
|
140 |
[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-medical_thesis_table2.jpg"]],
|
141 |
-
[[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-cat_report_12.png"]]
|
142 |
],
|
143 |
inputs=file_upload,
|
144 |
outputs=text_data_from_file_check,
|
@@ -187,6 +199,35 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green")) as demo
|
|
187 |
cache_examples=True,
|
188 |
)
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
# Callbacks
|
191 |
## OCR + Text2SQL
|
192 |
file_upload.upload(
|
@@ -208,6 +249,27 @@ with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green")) as demo
|
|
208 |
[cat_pain_assessment_barplot, cat_pain_assessment_score, cat_pain_assessment_explanation]
|
209 |
)
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
if __name__ == "__main__":
|
213 |
demo.queue().launch(max_threads=10)
|
|
|
9 |
|
10 |
ROOT_DIR = Path(__file__).resolve().parents[0]
|
11 |
|
12 |
+
def disable_btn():
|
13 |
+
return gr.Button.update(interactive=False)
|
14 |
+
|
15 |
+
def enable_btn():
|
16 |
+
return gr.Button.update(interactive=True)
|
17 |
|
18 |
def preview_uploaded_file(file_paths):
|
19 |
if file_paths:
|
|
|
77 |
# full_anwser += character
|
78 |
# yield full_anwser
|
79 |
|
80 |
+
def cat_report_explanation(data_array):
|
81 |
+
response = api_qa_cat_report(data_array)
|
82 |
+
full_anwser = ""
|
83 |
+
for character in response:
|
84 |
+
full_anwser += character
|
85 |
+
yield full_anwser
|
86 |
+
|
87 |
def draw_cat_pain_assessment_result(user_input_image):
|
88 |
if user_input_image:
|
89 |
json_result = api_model_cat_pain_assessment(user_input_image)
|
|
|
134 |
"""
|
135 |
with gr.Blocks(css=css, theme=gr.themes.Monochrome(neutral_hue="green")) as demo:
|
136 |
gr.HTML("<h1>GlobalModelAI AI Product Test</h1><p>Made by `GlobalModelAI Abao`</p>", elem_id="center")
|
137 |
+
|
138 |
with gr.Tab("OCR + Text2SQL"):
|
139 |
with gr.Row():
|
140 |
with gr.Column():
|
|
|
151 |
[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-esg_report_table3.png"]],
|
152 |
[[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-medical_thesis_table.png"],
|
153 |
[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-medical_thesis_table2.jpg"]],
|
|
|
154 |
],
|
155 |
inputs=file_upload,
|
156 |
outputs=text_data_from_file_check,
|
|
|
199 |
cache_examples=True,
|
200 |
)
|
201 |
|
202 |
+
with gr.Tab("Cat Report Explanation"):
|
203 |
+
gr.Markdown("## Cat Report Explanation", elem_id="center")
|
204 |
+
with gr.Row():
|
205 |
+
with gr.Column():
|
206 |
+
gr.Markdown("## Report Processing", elem_id="center")
|
207 |
+
catrep_ocr_model_choice = gr.Dropdown(label="Model", value="Gemini Pro Vision", choices=["GPT-4", "Gemini Pro Vision"])
|
208 |
+
catrep_file_preview = gr.Image(type="filepath", image_mode="RGB", sources=None, label="File Preview")
|
209 |
+
catrep_file_upload = gr.File(label="Upload File", file_types=["png", "jpg", "jpeg", "helc"], file_count='multiple')
|
210 |
+
catrep_button_generation_explanation = gr.Button("Start Explanation")
|
211 |
+
catrep_checkbox_open_data_check = gr.Checkbox(label="Open Data Check")
|
212 |
+
catrep_text_data_from_file_check = gr.Textbox(label="File Upload Status", interactive=False, visible=False)
|
213 |
+
gr.Examples(
|
214 |
+
examples=[
|
215 |
+
[[f"{ROOT_DIR}/data/image_for_test/screenshot_for_test-cat_report_12.png"]]
|
216 |
+
],
|
217 |
+
inputs=catrep_file_upload,
|
218 |
+
outputs=catrep_text_data_from_file_check,
|
219 |
+
fn=reference_from_file,
|
220 |
+
cache_examples=True,
|
221 |
+
elem_id="examples_file_to_ocr"
|
222 |
+
)
|
223 |
+
with gr.Column():
|
224 |
+
gr.Markdown("### View Explanation", elem_id="center")
|
225 |
+
catrep_textbox_explanation = gr.Textbox(
|
226 |
+
label="Explanation",
|
227 |
+
placeholder="Explanation will show here after you upload image & click the button",
|
228 |
+
interactive=False,
|
229 |
+
)
|
230 |
+
|
231 |
# Callbacks
|
232 |
## OCR + Text2SQL
|
233 |
file_upload.upload(
|
|
|
249 |
[cat_pain_assessment_barplot, cat_pain_assessment_score, cat_pain_assessment_explanation]
|
250 |
)
|
251 |
|
252 |
+
## Cat Report Explanation
|
253 |
+
catrep_file_upload.upload(
|
254 |
+
reference_from_file, [catrep_file_upload, catrep_ocr_model_choice], [catrep_text_data_from_file_check]
|
255 |
+
)
|
256 |
+
catrep_file_upload.change(
|
257 |
+
preview_uploaded_file, [catrep_file_upload], [catrep_file_preview]
|
258 |
+
)
|
259 |
+
catrep_ocr_model_choice.change(
|
260 |
+
reference_from_file, [catrep_file_upload, catrep_ocr_model_choice], [catrep_text_data_from_file_check]
|
261 |
+
)
|
262 |
+
catrep_checkbox_open_data_check.select(
|
263 |
+
open_data_check, [catrep_checkbox_open_data_check], [catrep_text_data_from_file_check]
|
264 |
+
)
|
265 |
+
catrep_button_generation_explanation.click(
|
266 |
+
disable_btn, None, None
|
267 |
+
).then(
|
268 |
+
cat_report_explanation, [catrep_text_data_from_file_check], [catrep_textbox_explanation]
|
269 |
+
).then(
|
270 |
+
enable_btn, None, None
|
271 |
+
)
|
272 |
+
|
273 |
|
274 |
if __name__ == "__main__":
|
275 |
demo.queue().launch(max_threads=10)
|