vaivskku commited on
Commit
0a1c8a2
ยท
1 Parent(s): 12da40e
Files changed (1) hide show
  1. app.py +49 -27
app.py CHANGED
@@ -6,7 +6,6 @@ import warnings
6
  import re
7
  import json
8
  import os
9
- import zipfile
10
  import numpy as np
11
  import pandas as pd
12
  from tqdm import tqdm
@@ -19,15 +18,6 @@ import itertools
19
  import sys
20
  import time
21
  import logging
22
- import subprocess
23
-
24
- result = subprocess.run(['git', 'lfs', 'pull'], capture_output=True, text=True)
25
-
26
- # ๋ช…๋ น์–ด ์‹คํ–‰ ๊ฒฐ๊ณผ ์ถœ๋ ฅ (์„ ํƒ ์‚ฌํ•ญ)
27
- if result.returncode == 0:
28
- print("LFS ํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋‹ค์šด๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
29
- else:
30
- print(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {result.stderr}")
31
 
32
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
33
  logger = logging.getLogger()
@@ -39,7 +29,7 @@ MAX_PATCHES = 512
39
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
 
41
  # Paths to the models
42
- ko_deplot_model_path = './deplot_model_ver_kor_24.7.25_refinetuning_epoch1.bin'
43
  aihub_deplot_model_path='./deplot_k.pt'
44
  t5_model_path = './ke_t5.pt'
45
 
@@ -649,7 +639,7 @@ class Highlighter:
649
 
650
  # 1. ๋ฐ์ดํ„ฐ ๋กœ๋“œ
651
  aihub_deplot_result_df = pd.read_csv('./aihub_deplot_result.csv')
652
- ko_deplot_result= './ko-deplot-base-pred-epoch3-refinetuning.json'
653
  unichart_result='./unichart_results.json'
654
 
655
  # 2. ์ฒดํฌํ•ด์•ผ ํ•˜๋Š” ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋กœ๋“œ
@@ -662,12 +652,11 @@ def load_image_checklist(file):
662
  # 3. ํ˜„์žฌ ์ธ๋ฑ์Šค๋ฅผ ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
663
  current_index = 0
664
  image_names = []
665
-
666
  def show_image(current_idx):
667
  image_name=image_names[current_idx]
668
- image_path = f"./top_20_percent_images/{image_name}.jpg"
669
  if not os.path.exists(image_path):
670
- image_path = f"./bottom_20_percent_images/{image_name}.jpg"
671
  return Image.open(image_path)
672
 
673
  # 4. ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
@@ -938,7 +927,7 @@ def file_selector(selector):
938
  return gr.File("./new_bottom_20_percent_images.txt")
939
  elif selector == "high score ์ฐจํŠธ":
940
  return gr.File("./new_top_20_percent_images.txt")
941
-
942
  def update_results(model_type):
943
  if "ko_deplot" == model_type:
944
  return gr.update(visible=True),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
@@ -948,6 +937,34 @@ def update_results(model_type):
948
  return gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
949
  else:
950
  return gr.update(visible=True), gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
 
952
  def display_image(image_file):
953
  image=Image.open(image_file)
@@ -1000,7 +1017,11 @@ def handle_chart_type_change(chart_type,all_file_path):
1000
  image=show_image(current_index)
1001
  return image,image_names[current_index]
1002
 
1003
- with gr.Blocks() as iface:
 
 
 
 
1004
  mode=gr.State("image_upload")
1005
  with gr.Row():
1006
  with gr.Column():
@@ -1016,7 +1037,7 @@ with gr.Blocks() as iface:
1016
  file_uploader= gr.File(file_count="single", file_types=[".txt"], visible=False)
1017
  file_upload_option=gr.Radio(choices=["low score ์ฐจํŠธ","high score ์ฐจํŠธ"],label="ํŒŒ์ผ ์—…๋กœ๋“œ ์˜ต์…˜",visible=False)
1018
  chart_type = gr.Dropdown(["์ผ๋ฐ˜ ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•","๋ˆ„์  ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•","100% ๊ธฐ์ค€ ๋ˆ„์  ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•", "์ผ๋ฐ˜ ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","๋ˆ„์  ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","100% ๊ธฐ์ค€ ๋ˆ„์  ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","์„ ํ˜•", "์›ํ˜•", "๊ธฐํƒ€ ๋ฐฉ์‚ฌํ˜•", "๊ธฐํƒ€ ํ˜ผํ•ฉํ˜•", "์ „์ฒด"], label="Chart Type", value="all")
1019
- model_type=gr.Dropdown(["ko_deplot","aihub_deplot","unichart","all"],label="model")
1020
  image_displayer=gr.Image(visible=True)
1021
  with gr.Row():
1022
  pre_button=gr.Button("์ด์ „",interactive="False")
@@ -1026,17 +1047,17 @@ with gr.Blocks() as iface:
1026
  #file_button.click(interface_selector, inputs=gr.State("ํŒŒ์ผ ์—…๋กœ๋“œ"), outputs=[image_uploader, file_uploader,mode,mode_label,image_name])
1027
  inference_button=gr.Button("์ถ”๋ก ")
1028
  with gr.Column():
1029
- ko_deplot_generated_table=gr.DataFrame(visible=False,label="ko-deplot ์ถ”๋ก  ๊ฒฐ๊ณผ")
1030
- aihub_deplot_generated_table=gr.DataFrame(visible=False,label="aihub-deplot ์ถ”๋ก  ๊ฒฐ๊ณผ")
1031
- unichart_generated_table=gr.DataFrame(visible=False,label="unichart ์ถ”๋ก  ๊ฒฐ๊ณผ")
1032
  with gr.Column():
1033
- ko_deplot_label_table=gr.DataFrame(visible=False,label="ko-deplot ์ •๋‹ตํ…Œ์ด๋ธ”")
1034
- aihub_deplot_label_table=gr.DataFrame(visible=False,label="aihub-deplot ์ •๋‹ตํ…Œ์ด๋ธ”")
1035
- unichart_label_table=gr.DataFrame(visible=False,label="unichart ์ •๋‹ตํ…Œ์ด๋ธ”")
1036
  with gr.Column():
1037
- ko_deplot_score_table=gr.DataFrame(visible=False,label="ko_deplot ์ ์ˆ˜")
1038
- aihub_deplot_score_table=gr.DataFrame(visible=False,label="aihub_deplot ์ ์ˆ˜")
1039
- unichart_score_table=gr.DataFrame(visible=False,label="unichart ์ ์ˆ˜")
1040
  model_type.change(
1041
  update_results,
1042
  inputs=[model_type],
@@ -1066,6 +1087,7 @@ if __name__ == "__main__":
1066
  print("Launching Gradio interface...")
1067
  sys.stdout.flush() # stdout ๋ฒ„ํผ๋ฅผ ๋น„์›๋‹ˆ๋‹ค.
1068
  iface.launch(share=True)
 
1069
  time.sleep(2) # Gradio URL์ด ์ถœ๋ ฅ๋  ๋•Œ๊นŒ์ง€ ์ž ์‹œ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.
1070
  sys.stdout.flush() # ๋‹ค์‹œ stdout ๋ฒ„ํผ๋ฅผ ๋น„์›๋‹ˆ๋‹ค.
1071
  # Gradio๊ฐ€ ์ œ๊ณตํ•˜๋Š” URLs์„ ํŒŒ์ผ์— ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.
 
6
  import re
7
  import json
8
  import os
 
9
  import numpy as np
10
  import pandas as pd
11
  from tqdm import tqdm
 
18
  import sys
19
  import time
20
  import logging
 
 
 
 
 
 
 
 
 
21
 
22
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
23
  logger = logging.getLogger()
 
29
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
30
 
31
  # Paths to the models
32
+ ko_deplot_model_path = './deplot_model_ver_kor_24.7.25_refinetuning_epoch3.bin'
33
  aihub_deplot_model_path='./deplot_k.pt'
34
  t5_model_path = './ke_t5.pt'
35
 
 
639
 
640
  # 1. ๋ฐ์ดํ„ฐ ๋กœ๋“œ
641
  aihub_deplot_result_df = pd.read_csv('./aihub_deplot_result.csv')
642
+ ko_deplot_result= './ko-deplot-base-pred-epoch1-refinetuning.json'
643
  unichart_result='./unichart_results.json'
644
 
645
  # 2. ์ฒดํฌํ•ด์•ผ ํ•˜๋Š” ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋กœ๋“œ
 
652
  # 3. ํ˜„์žฌ ์ธ๋ฑ์Šค๋ฅผ ์ถ”์ ํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
653
  current_index = 0
654
  image_names = []
 
655
  def show_image(current_idx):
656
  image_name=image_names[current_idx]
657
+ image_path = f"./images/{image_name}.jpg"
658
  if not os.path.exists(image_path):
659
+ raise FileNotFoundError(f"Image file not found: {image_path}")
660
  return Image.open(image_path)
661
 
662
  # 4. ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
 
927
  return gr.File("./new_bottom_20_percent_images.txt")
928
  elif selector == "high score ์ฐจํŠธ":
929
  return gr.File("./new_top_20_percent_images.txt")
930
+ '''
931
  def update_results(model_type):
932
  if "ko_deplot" == model_type:
933
  return gr.update(visible=True),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False)
 
937
  return gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True),gr.update(visible=True),gr.update(visible=False),gr.update(visible=False),gr.update(visible=True)
938
  else:
939
  return gr.update(visible=True), gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True)
940
+ '''
941
+
942
+ def update_results(selected_models):
943
+ # Create a visibility list initialized to False for all components
944
+ visibility = [False] * 9
945
+
946
+ # Update visibility based on the selected models
947
+ if "ko_deplot" in selected_models:
948
+ visibility[0] = True # ko_deplot_generated_table
949
+ visibility[1] = True # ko_deplot_score_table
950
+ visibility[6] = True # ko_deplot_label_table
951
+
952
+ if "aihub_deplot" in selected_models:
953
+ visibility[2] = True # aihub_deplot_generated_table
954
+ visibility[3] = True # aihub_deplot_score_table
955
+ visibility[7] = True # aihub_deplot_label_table
956
+
957
+ if "unichart" in selected_models:
958
+ visibility[4] = True # unichart_generated_table
959
+ visibility[5] = True # unichart_score_table
960
+ visibility[8] = True # unichart_label_table
961
+
962
+ if "all" in selected_models:
963
+ visibility=[True]*9
964
+
965
+ # Return gr.update for each component with the corresponding visibility status
966
+ return tuple(gr.update(visible=v) for v in visibility)
967
+
968
 
969
  def display_image(image_file):
970
  image=Image.open(image_file)
 
1017
  image=show_image(current_index)
1018
  return image,image_names[current_index]
1019
 
1020
+ css = """
1021
+ #warning span {font-size: 24px !important}
1022
+ """
1023
+
1024
+ with gr.Blocks(css=css) as iface:
1025
  mode=gr.State("image_upload")
1026
  with gr.Row():
1027
  with gr.Column():
 
1037
  file_uploader= gr.File(file_count="single", file_types=[".txt"], visible=False)
1038
  file_upload_option=gr.Radio(choices=["low score ์ฐจํŠธ","high score ์ฐจํŠธ"],label="ํŒŒ์ผ ์—…๋กœ๋“œ ์˜ต์…˜",visible=False)
1039
  chart_type = gr.Dropdown(["์ผ๋ฐ˜ ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•","๋ˆ„์  ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•","100% ๊ธฐ์ค€ ๋ˆ„์  ๊ฐ€๋กœ ๋ง‰๋Œ€ํ˜•", "์ผ๋ฐ˜ ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","๋ˆ„์  ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","100% ๊ธฐ์ค€ ๋ˆ„์  ์„ธ๋กœ ๋ง‰๋Œ€ํ˜•","์„ ํ˜•", "์›ํ˜•", "๊ธฐํƒ€ ๋ฐฉ์‚ฌํ˜•", "๊ธฐํƒ€ ํ˜ผํ•ฉํ˜•", "์ „์ฒด"], label="Chart Type", value="all")
1040
+ model_type=gr.Dropdown(["ko_deplot","aihub_deplot","unichart","all"],label="model",multiselect=True)
1041
  image_displayer=gr.Image(visible=True)
1042
  with gr.Row():
1043
  pre_button=gr.Button("์ด์ „",interactive="False")
 
1047
  #file_button.click(interface_selector, inputs=gr.State("ํŒŒ์ผ ์—…๋กœ๋“œ"), outputs=[image_uploader, file_uploader,mode,mode_label,image_name])
1048
  inference_button=gr.Button("์ถ”๋ก ")
1049
  with gr.Column():
1050
+ ko_deplot_generated_table=gr.DataFrame(visible=False,label="ko-deplot ์ถ”๋ก  ๊ฒฐ๊ณผ",elem_id="warning")
1051
+ aihub_deplot_generated_table=gr.DataFrame(visible=False,label="aihub-deplot ์ถ”๋ก  ๊ฒฐ๊ณผ",elem_id="warning")
1052
+ unichart_generated_table=gr.DataFrame(visible=False,label="unichart ์ถ”๋ก  ๊ฒฐ๊ณผ",elem_id="warning")
1053
  with gr.Column():
1054
+ ko_deplot_label_table=gr.DataFrame(visible=False,label="ko-deplot ์ •๋‹ตํ…Œ์ด๋ธ”",elem_id="warning")
1055
+ aihub_deplot_label_table=gr.DataFrame(visible=False,label="aihub-deplot ์ •๋‹ตํ…Œ์ด๋ธ”",elem_id="warning")
1056
+ unichart_label_table=gr.DataFrame(visible=False,label="unichart ์ •๋‹ตํ…Œ์ด๋ธ”",elem_id="warning")
1057
  with gr.Column():
1058
+ ko_deplot_score_table=gr.DataFrame(visible=False,label="ko_deplot ์ ์ˆ˜",elem_id="warning")
1059
+ aihub_deplot_score_table=gr.DataFrame(visible=False,label="aihub_deplot ์ ์ˆ˜",elem_id="warning")
1060
+ unichart_score_table=gr.DataFrame(visible=False,label="unichart ์ ์ˆ˜",elem_id="warning")
1061
  model_type.change(
1062
  update_results,
1063
  inputs=[model_type],
 
1087
  print("Launching Gradio interface...")
1088
  sys.stdout.flush() # stdout ๋ฒ„ํผ๋ฅผ ๋น„์›๋‹ˆ๋‹ค.
1089
  iface.launch(share=True)
1090
+ #iface.launch(share=False,server_name="115.145.230.14",server_port=8080)
1091
  time.sleep(2) # Gradio URL์ด ์ถœ๋ ฅ๋  ๋•Œ๊นŒ์ง€ ์ž ์‹œ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.
1092
  sys.stdout.flush() # ๋‹ค์‹œ stdout ๋ฒ„ํผ๋ฅผ ๋น„์›๋‹ˆ๋‹ค.
1093
  # Gradio๊ฐ€ ์ œ๊ณตํ•˜๋Š” URLs์„ ํŒŒ์ผ์— ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.