Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -500,18 +500,15 @@ def table_datapoints_precision_recall_per_point( # 각각 계산...
|
|
| 500 |
number_theta = 0.1,
|
| 501 |
):
|
| 502 |
"""Computes precisin recall and F1 metrics given two flattened tables.
|
| 503 |
-
|
| 504 |
Parses each string into a dictionary of keys and values using row and column
|
| 505 |
headers. Then we match keys between the two dicts as long as their relative
|
| 506 |
levenshtein distance is below a threshold. Values are also compared with
|
| 507 |
ANLS if strings or relative distance if they are numeric.
|
| 508 |
-
|
| 509 |
Args:
|
| 510 |
targets: list of list of strings.
|
| 511 |
predictions: list of strings.
|
| 512 |
text_theta: relative edit distance above this is set to the maximum of 1.
|
| 513 |
number_theta: relative error rate above this is set to the maximum of 1.
|
| 514 |
-
|
| 515 |
Returns:
|
| 516 |
Dictionary with per-point precision, recall and F1
|
| 517 |
"""
|
|
@@ -538,16 +535,13 @@ def table_datapoints_precision_recall( # deplot 성능지표
|
|
| 538 |
number_theta = 0.1,
|
| 539 |
):
|
| 540 |
"""Aggregated version of table_datapoints_precision_recall_per_point().
|
| 541 |
-
|
| 542 |
Same as table_datapoints_precision_recall_per_point() but returning aggregated
|
| 543 |
scores instead of per-point scores.
|
| 544 |
-
|
| 545 |
Args:
|
| 546 |
targets: list of list of strings.
|
| 547 |
predictions: list of strings.
|
| 548 |
text_theta: relative edit distance above this is set to the maximum of 1.
|
| 549 |
number_theta: relative error rate above this is set to the maximum of 1.
|
| 550 |
-
|
| 551 |
Returns:
|
| 552 |
Dictionary with aggregated precision, recall and F1
|
| 553 |
"""
|
|
@@ -751,36 +745,29 @@ def non_real_time_check(file):
|
|
| 751 |
round(aihub_deplot_RMS['table_datapoints_f1'],1)
|
| 752 |
]
|
| 753 |
})
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
except Exception as e:
|
| 759 |
-
return None,None,None,None,None,None,None,None,None,ko_deplot_generated_table,unichart_generated_table,1
|
| 760 |
-
|
| 761 |
-
#ko_deplot_generated_df=ko_deplot_convert_to_dataframe(ko_deplot_generated_table)
|
| 762 |
-
#aihub_deplot_generated_df=aihub_deplot_convert_to_dataframe(aihub_deplot_generated_table)
|
| 763 |
-
#unichart_generated_df=unichart_convert_to_dataframe(unichart_generated_table)
|
| 764 |
-
|
| 765 |
ko_deplot_labeling_df=ko_deplot_convert_to_dataframe2(ko_deplot_labeling_str)
|
| 766 |
-
|
| 767 |
unichart_labeling_df=unichart_convert_to_dataframe(unichart_labeling_str)
|
| 768 |
|
| 769 |
ko_deplot_generated_df_row=ko_deplot_generated_df.shape[0]
|
| 770 |
-
|
| 771 |
unichart_generated_df_row=unichart_generated_df.shape[0]
|
| 772 |
|
| 773 |
|
| 774 |
styled_ko_deplot_table=ko_deplot_generated_df.style.applymap(highlighter1.compare_and_highlight,target_table=ko_deplot_labeling_df,pred_table_row=ko_deplot_generated_df_row,props='color:red')
|
| 775 |
|
| 776 |
|
| 777 |
-
|
| 778 |
|
| 779 |
|
| 780 |
styled_unichart_table=unichart_generated_df.style.applymap(highlighter3.compare_and_highlight,target_table=unichart_labeling_df,pred_table_row=unichart_generated_df_row,props='color:red')
|
| 781 |
|
| 782 |
#return ko_deplot_convert_to_dataframe(ko_deplot_generated_table), aihub_deplot_convert_to_dataframe(aihub_deplot_generated_table), aihub_deplot_convert_to_dataframe(label_table), ko_deplot_score_table, aihub_deplot_score_table
|
| 783 |
-
return gr.DataFrame(styled_ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)"),
|
| 784 |
|
| 785 |
|
| 786 |
def ko_deplot_display_results(index):
|
|
@@ -839,17 +826,11 @@ def real_time_check(image_file):
|
|
| 839 |
del parts[-1]
|
| 840 |
result_model1="\n".join(parts)
|
| 841 |
ko_deplot_generated_title=result_model1.split("\n")[0].split(" | ")[1]
|
| 842 |
-
|
| 843 |
|
| 844 |
result_model3=predict_model3(image)
|
| 845 |
-
|
| 846 |
unichart_generated_title=result_model3.split(" & ")[0].split(" | ")[1]
|
| 847 |
-
|
| 848 |
-
try:
|
| 849 |
-
ko_deplot_table=ko_deplot_convert_to_dataframe2(result_model1)
|
| 850 |
-
unichart_table=unichart_convert_to_dataframe(result_model3)
|
| 851 |
-
except Exception as e:
|
| 852 |
-
return None,None,None,None,None,None,None,None,None,result_model1,result_model3,1
|
| 853 |
|
| 854 |
#aihub_labeling_data_json="./labeling_data/"+file_name+".json"
|
| 855 |
if os.path.basename(image_file.name).startswith("C_Source"):
|
|
@@ -901,22 +882,16 @@ def real_time_check(image_file):
|
|
| 901 |
unichart_generated_df_row=unichart_table.shape[0]
|
| 902 |
styled_ko_deplot_table=ko_deplot_table.style.applymap(highlighter1.compare_and_highlight,target_table=ko_deplot_label_table,pred_table_row=ko_deplot_generated_df_row,props='color:red')
|
| 903 |
styled_unichart_table=unichart_table.style.applymap(highlighter3.compare_and_highlight,target_table=unichart_label_table,pred_table_row=unichart_generated_df_row,props='color:red')
|
| 904 |
-
return gr.DataFrame(styled_ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)") ,None,gr.DataFrame(styled_unichart_table,label=unichart_generated_title+"(VAIV_UniChart 추론 결과)"),gr.DataFrame(ko_deplot_label_table,label=ko_deplot_label_title+"(VAIV_DePlot 정답 테이블)"),None,gr.DataFrame(unichart_label_table,label=unichart_label_title+"(VAIV_UniChart 정답 테이블)"),ko_deplot_score_table,None,unichart_score_table
|
| 905 |
else:
|
| 906 |
-
return gr.DataFrame(ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)"),None,gr.DataFrame(unichart_table,label=unichart_generated_title+"(VAIV_UniChart 추론 결과)"),None,None,None,None,None,None
|
| 907 |
def inference(mode,image_uploader,file_uploader):
|
| 908 |
if(mode=="이미지 업로드"):
|
| 909 |
-
ko_deplot_table, aihub_deplot_table, unichart_table, ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table
|
| 910 |
-
|
| 911 |
-
return ko_deplot_table, aihub_deplot_table, unichart_table,ko_deplot_label_table, aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table,gr.Text(ko_deplot_generated_txt,visible=True),gr.Text(unichart_generated_txt,visible=True)
|
| 912 |
-
else:
|
| 913 |
-
return ko_deplot_table, aihub_deplot_table, unichart_table,ko_deplot_label_table, aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table,gr.update(visible=False),gr.update(visible=False)
|
| 914 |
else:
|
| 915 |
-
styled_ko_deplot_table,styled_aihub_deplot_table,styled_unichart_table,ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table,aihub_deplot_score_table, unichart_score_table
|
| 916 |
-
|
| 917 |
-
return styled_ko_deplot_table, styled_aihub_deplot_table, styled_unichart_table,ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table, unichart_score_table,gr.Text(ko_deplot_generated_txt,visible=True),gr.Text(unichart_generated_txt,visible=True)
|
| 918 |
-
else:
|
| 919 |
-
return styled_ko_deplot_table, styled_aihub_deplot_table, styled_unichart_table,ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table, unichart_score_table,gr.update(visible=False),gr.update(visible=False)
|
| 920 |
def interface_selector(selector):
|
| 921 |
if selector == "이미지 업로드":
|
| 922 |
return gr.update(visible=True),gr.update(visible=False),gr.State("image_upload"),gr.update(visible=False),gr.update(visible=False),gr.File("./new_top_20_percent_images.txt"),"high score 차트"
|
|
@@ -1059,8 +1034,6 @@ with gr.Blocks(css=css) as iface:
|
|
| 1059 |
ko_deplot_generated_table=gr.DataFrame(visible=True,label="VAIV_DePlot 추론 결과",elem_classes="dataframe-class")
|
| 1060 |
aihub_deplot_generated_table=gr.DataFrame(visible=False,label="aihub-deplot 추론 결과",elem_classes="dataframe-class")
|
| 1061 |
unichart_generated_table=gr.DataFrame(visible=False,label="VAIV_UniChart 추론 결과",elem_classes="dataframe-class")
|
| 1062 |
-
ko_deplot_generated_txt=gr.Text(visible=False,label="VAIV_DePlot 추론 결과")
|
| 1063 |
-
unichart_generated_txt=gr.Text(visible=False,label="VAIV_UniChart 추론 결과")
|
| 1064 |
with gr.Column():
|
| 1065 |
ko_deplot_label_table=gr.DataFrame(visible=True,label="VAIV_DePlot 정답테이블",elem_classes="dataframe-class")
|
| 1066 |
aihub_deplot_label_table=gr.DataFrame(visible=False,label="aihub-deplot 정답테이블",elem_classes="dataframe-class")
|
|
@@ -1092,7 +1065,7 @@ with gr.Blocks(css=css) as iface:
|
|
| 1092 |
file_uploader.change(display_image_in_file,inputs=[file_uploader],outputs=[image_displayer,image_name])
|
| 1093 |
pre_button.click(previous_image, outputs=[image_displayer,image_name,pre_button,next_button])
|
| 1094 |
next_button.click(next_image, outputs=[image_displayer,image_name,pre_button,next_button])
|
| 1095 |
-
inference_button.click(inference,inputs=[upload_option,image_uploader,file_uploader],outputs=[ko_deplot_generated_table, aihub_deplot_generated_table, unichart_generated_table, ko_deplot_label_table, aihub_deplot_label_table, unichart_label_table, ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table
|
| 1096 |
|
| 1097 |
if __name__ == "__main__":
|
| 1098 |
print("Launching Gradio interface...")
|
|
@@ -1104,4 +1077,4 @@ if __name__ == "__main__":
|
|
| 1104 |
# Gradio가 제공하는 URLs을 파일에 기록합니다.
|
| 1105 |
with open("gradio_url.log", "w") as f:
|
| 1106 |
print(iface.local_url, file=f)
|
| 1107 |
-
print(iface.share_url, file=f)
|
|
|
|
| 500 |
number_theta = 0.1,
|
| 501 |
):
|
| 502 |
"""Computes precisin recall and F1 metrics given two flattened tables.
|
|
|
|
| 503 |
Parses each string into a dictionary of keys and values using row and column
|
| 504 |
headers. Then we match keys between the two dicts as long as their relative
|
| 505 |
levenshtein distance is below a threshold. Values are also compared with
|
| 506 |
ANLS if strings or relative distance if they are numeric.
|
|
|
|
| 507 |
Args:
|
| 508 |
targets: list of list of strings.
|
| 509 |
predictions: list of strings.
|
| 510 |
text_theta: relative edit distance above this is set to the maximum of 1.
|
| 511 |
number_theta: relative error rate above this is set to the maximum of 1.
|
|
|
|
| 512 |
Returns:
|
| 513 |
Dictionary with per-point precision, recall and F1
|
| 514 |
"""
|
|
|
|
| 535 |
number_theta = 0.1,
|
| 536 |
):
|
| 537 |
"""Aggregated version of table_datapoints_precision_recall_per_point().
|
|
|
|
| 538 |
Same as table_datapoints_precision_recall_per_point() but returning aggregated
|
| 539 |
scores instead of per-point scores.
|
|
|
|
| 540 |
Args:
|
| 541 |
targets: list of list of strings.
|
| 542 |
predictions: list of strings.
|
| 543 |
text_theta: relative edit distance above this is set to the maximum of 1.
|
| 544 |
number_theta: relative error rate above this is set to the maximum of 1.
|
|
|
|
| 545 |
Returns:
|
| 546 |
Dictionary with aggregated precision, recall and F1
|
| 547 |
"""
|
|
|
|
| 745 |
round(aihub_deplot_RMS['table_datapoints_f1'],1)
|
| 746 |
]
|
| 747 |
})
|
| 748 |
+
|
| 749 |
+
ko_deplot_generated_df=ko_deplot_convert_to_dataframe(ko_deplot_generated_table)
|
| 750 |
+
aihub_deplot_generated_df=aihub_deplot_convert_to_dataframe(aihub_deplot_generated_table)
|
| 751 |
+
unichart_generated_df=unichart_convert_to_dataframe(unichart_generated_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
ko_deplot_labeling_df=ko_deplot_convert_to_dataframe2(ko_deplot_labeling_str)
|
| 753 |
+
aihub_deplot_labeling_df=aihub_deplot_convert_to_dataframe(aihub_deplot_label_table)
|
| 754 |
unichart_labeling_df=unichart_convert_to_dataframe(unichart_labeling_str)
|
| 755 |
|
| 756 |
ko_deplot_generated_df_row=ko_deplot_generated_df.shape[0]
|
| 757 |
+
aihub_deplot_generated_df_row=aihub_deplot_generated_df.shape[0]
|
| 758 |
unichart_generated_df_row=unichart_generated_df.shape[0]
|
| 759 |
|
| 760 |
|
| 761 |
styled_ko_deplot_table=ko_deplot_generated_df.style.applymap(highlighter1.compare_and_highlight,target_table=ko_deplot_labeling_df,pred_table_row=ko_deplot_generated_df_row,props='color:red')
|
| 762 |
|
| 763 |
|
| 764 |
+
styled_aihub_deplot_table=aihub_deplot_generated_df.style.applymap(highlighter2.compare_and_highlight,target_table=aihub_deplot_labeling_df,pred_table_row=aihub_deplot_generated_df_row,props='color:red')
|
| 765 |
|
| 766 |
|
| 767 |
styled_unichart_table=unichart_generated_df.style.applymap(highlighter3.compare_and_highlight,target_table=unichart_labeling_df,pred_table_row=unichart_generated_df_row,props='color:red')
|
| 768 |
|
| 769 |
#return ko_deplot_convert_to_dataframe(ko_deplot_generated_table), aihub_deplot_convert_to_dataframe(aihub_deplot_generated_table), aihub_deplot_convert_to_dataframe(label_table), ko_deplot_score_table, aihub_deplot_score_table
|
| 770 |
+
return gr.DataFrame(styled_ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)"),gr.DataFrame(styled_aihub_deplot_table,label=aihub_deplot_generated_title+"(aihub deplot 추론 결과)"),gr.DataFrame(styled_unichart_table,label="제목:"+unichart_generated_title+"(VAIV_UniChart 추론 결과)"),gr.DataFrame(ko_deplot_labeling_df,label=ko_deplot_label_title+"(VAIV_DePlot 정답 테이블)"), gr.DataFrame(aihub_deplot_labeling_df,label=aihub_deplot_label_title+"(aihub deplot 정답 테이블)"),gr.DataFrame(unichart_labeling_df,label="제목:"+unichart_label_title+"(VAIV_UniChart 정답 테이블)"),ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table
|
| 771 |
|
| 772 |
|
| 773 |
def ko_deplot_display_results(index):
|
|
|
|
| 826 |
del parts[-1]
|
| 827 |
result_model1="\n".join(parts)
|
| 828 |
ko_deplot_generated_title=result_model1.split("\n")[0].split(" | ")[1]
|
| 829 |
+
ko_deplot_table=ko_deplot_convert_to_dataframe2(result_model1)
|
| 830 |
|
| 831 |
result_model3=predict_model3(image)
|
| 832 |
+
unichart_table=unichart_convert_to_dataframe(result_model3)
|
| 833 |
unichart_generated_title=result_model3.split(" & ")[0].split(" | ")[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 834 |
|
| 835 |
#aihub_labeling_data_json="./labeling_data/"+file_name+".json"
|
| 836 |
if os.path.basename(image_file.name).startswith("C_Source"):
|
|
|
|
| 882 |
unichart_generated_df_row=unichart_table.shape[0]
|
| 883 |
styled_ko_deplot_table=ko_deplot_table.style.applymap(highlighter1.compare_and_highlight,target_table=ko_deplot_label_table,pred_table_row=ko_deplot_generated_df_row,props='color:red')
|
| 884 |
styled_unichart_table=unichart_table.style.applymap(highlighter3.compare_and_highlight,target_table=unichart_label_table,pred_table_row=unichart_generated_df_row,props='color:red')
|
| 885 |
+
return gr.DataFrame(styled_ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)") ,None,gr.DataFrame(styled_unichart_table,label=unichart_generated_title+"(VAIV_UniChart 추론 결과)"),gr.DataFrame(ko_deplot_label_table,label=ko_deplot_label_title+"(VAIV_DePlot 정답 테이블)"),None,gr.DataFrame(unichart_label_table,label=unichart_label_title+"(VAIV_UniChart 정답 테이블)"),ko_deplot_score_table,None,unichart_score_table
|
| 886 |
else:
|
| 887 |
+
return gr.DataFrame(ko_deplot_table,label=ko_deplot_generated_title+"(VAIV_DePlot 추론 결과)"),None,gr.DataFrame(unichart_table,label=unichart_generated_title+"(VAIV_UniChart 추론 결과)"),None,None,None,None,None,None
|
| 888 |
def inference(mode,image_uploader,file_uploader):
|
| 889 |
if(mode=="이미지 업로드"):
|
| 890 |
+
ko_deplot_table, aihub_deplot_table, unichart_table, ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table= real_time_check(image_uploader)
|
| 891 |
+
return ko_deplot_table, aihub_deplot_table, unichart_table,ko_deplot_label_table, aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table
|
|
|
|
|
|
|
|
|
|
| 892 |
else:
|
| 893 |
+
styled_ko_deplot_table,styled_aihub_deplot_table,styled_unichart_table,ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table,aihub_deplot_score_table, unichart_score_table=non_real_time_check(file_uploader)
|
| 894 |
+
return styled_ko_deplot_table, styled_aihub_deplot_table, styled_unichart_table,ko_deplot_label_table,aihub_deplot_label_table,unichart_label_table,ko_deplot_score_table, aihub_deplot_score_table, unichart_score_table
|
|
|
|
|
|
|
|
|
|
| 895 |
def interface_selector(selector):
|
| 896 |
if selector == "이미지 업로드":
|
| 897 |
return gr.update(visible=True),gr.update(visible=False),gr.State("image_upload"),gr.update(visible=False),gr.update(visible=False),gr.File("./new_top_20_percent_images.txt"),"high score 차트"
|
|
|
|
| 1034 |
ko_deplot_generated_table=gr.DataFrame(visible=True,label="VAIV_DePlot 추론 결과",elem_classes="dataframe-class")
|
| 1035 |
aihub_deplot_generated_table=gr.DataFrame(visible=False,label="aihub-deplot 추론 결과",elem_classes="dataframe-class")
|
| 1036 |
unichart_generated_table=gr.DataFrame(visible=False,label="VAIV_UniChart 추론 결과",elem_classes="dataframe-class")
|
|
|
|
|
|
|
| 1037 |
with gr.Column():
|
| 1038 |
ko_deplot_label_table=gr.DataFrame(visible=True,label="VAIV_DePlot 정답테이블",elem_classes="dataframe-class")
|
| 1039 |
aihub_deplot_label_table=gr.DataFrame(visible=False,label="aihub-deplot 정답테이블",elem_classes="dataframe-class")
|
|
|
|
| 1065 |
file_uploader.change(display_image_in_file,inputs=[file_uploader],outputs=[image_displayer,image_name])
|
| 1066 |
pre_button.click(previous_image, outputs=[image_displayer,image_name,pre_button,next_button])
|
| 1067 |
next_button.click(next_image, outputs=[image_displayer,image_name,pre_button,next_button])
|
| 1068 |
+
inference_button.click(inference,inputs=[upload_option,image_uploader,file_uploader],outputs=[ko_deplot_generated_table, aihub_deplot_generated_table, unichart_generated_table, ko_deplot_label_table, aihub_deplot_label_table, unichart_label_table, ko_deplot_score_table, aihub_deplot_score_table,unichart_score_table])
|
| 1069 |
|
| 1070 |
if __name__ == "__main__":
|
| 1071 |
print("Launching Gradio interface...")
|
|
|
|
| 1077 |
# Gradio가 제공하는 URLs을 파일에 기록합니다.
|
| 1078 |
with open("gradio_url.log", "w") as f:
|
| 1079 |
print(iface.local_url, file=f)
|
| 1080 |
+
print(iface.share_url, file=f)
|