ZeroCommand commited on
Commit
3025552
1 Parent(s): 0444141

fix feature mapping selection bug

Browse files
app.py CHANGED
@@ -1,14 +1,10 @@
1
  import atexit
2
- import threading
3
-
4
  import gradio as gr
5
 
6
  from app_leaderboard import get_demo as get_demo_leaderboard
7
  from app_text_classification import get_demo as get_demo_text_classification
8
  from run_jobs import start_process_run_job, stop_thread
9
 
10
- if threading.current_thread() is not threading.main_thread():
11
- t = threading.current_thread()
12
  try:
13
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green")) as demo:
14
  with gr.Tab("Text Classification"):
@@ -22,6 +18,6 @@ try:
22
  demo.launch(share=False)
23
  atexit.register(stop_thread)
24
 
25
- except Exception:
26
- print("stop background thread")
27
  stop_thread()
 
1
  import atexit
 
 
2
  import gradio as gr
3
 
4
  from app_leaderboard import get_demo as get_demo_leaderboard
5
  from app_text_classification import get_demo as get_demo_text_classification
6
  from run_jobs import start_process_run_job, stop_thread
7
 
 
 
8
  try:
9
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="green")) as demo:
10
  with gr.Tab("Text Classification"):
 
18
  demo.launch(share=False)
19
  atexit.register(stop_thread)
20
 
21
+ except Exception as e:
22
+ print("stop background thread: ", e)
23
  stop_thread()
app_text_classification.py CHANGED
@@ -119,6 +119,19 @@ def get_demo(demo):
119
  ],
120
  )
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  gr.on(
123
  triggers=[
124
  model_id_input.change,
 
119
  ],
120
  )
121
 
122
+ # label.change sometimes does not pass the changed value
123
+ gr.on(
124
+ triggers=[label.input for label in column_mappings],
125
+ fn=write_column_mapping_to_config,
126
+ inputs=[
127
+ dataset_id_input,
128
+ dataset_config_input,
129
+ dataset_split_input,
130
+ uid_label,
131
+ *column_mappings,
132
+ ],
133
+ )
134
+
135
  gr.on(
136
  triggers=[
137
  model_id_input.change,
io_utils.py CHANGED
@@ -120,6 +120,8 @@ def pop_job_from_pipe():
120
  job_info = pipe.jobs.pop()
121
  write_log_to_user_file(job_info[0], f"Running job id {job_info[0]}\n")
122
  command = job_info[1]
 
 
123
 
124
  log_file = open(f"./tmp/{job_info[0]}_log", "a")
125
  subprocess.Popen(
 
120
  job_info = pipe.jobs.pop()
121
  write_log_to_user_file(job_info[0], f"Running job id {job_info[0]}\n")
122
  command = job_info[1]
123
+ print(f"Running job id {job_info[0]}")
124
+ print(f"Running command {command}")
125
 
126
  log_file = open(f"./tmp/{job_info[0]}_log", "a")
127
  subprocess.Popen(
run_jobs.py CHANGED
@@ -1,6 +1,6 @@
1
  import threading
2
  import time
3
-
4
  import pipe
5
  from io_utils import pop_job_from_pipe
6
 
@@ -9,7 +9,7 @@ is_running = False
9
 
10
  def start_process_run_job():
11
  try:
12
- print("Running jobs in thread")
13
  global thread, is_running
14
  thread = threading.Thread(target=run_job)
15
  thread.daemon = True
@@ -22,7 +22,7 @@ def start_process_run_job():
22
 
23
 
24
  def stop_thread():
25
- print("Stop thread")
26
  global is_running
27
  is_running = False
28
 
@@ -34,6 +34,6 @@ def run_job():
34
  pop_job_from_pipe()
35
  time.sleep(10)
36
  except KeyboardInterrupt:
37
- print("KeyboardInterrupt stop background thread")
38
  is_running = False
39
  break
 
1
  import threading
2
  import time
3
+ import logging
4
  import pipe
5
  from io_utils import pop_job_from_pipe
6
 
 
9
 
10
  def start_process_run_job():
11
  try:
12
+ logging.debug("Running jobs in thread")
13
  global thread, is_running
14
  thread = threading.Thread(target=run_job)
15
  thread.daemon = True
 
22
 
23
 
24
  def stop_thread():
25
+ logging.debug("Stop thread")
26
  global is_running
27
  is_running = False
28
 
 
34
  pop_job_from_pipe()
35
  time.sleep(10)
36
  except KeyboardInterrupt:
37
+ logging.debug("KeyboardInterrupt stop background thread")
38
  is_running = False
39
  break
text_classification_ui_helpers.py CHANGED
@@ -24,7 +24,7 @@ HF_WRITE_TOKEN = "HF_WRITE_TOKEN"
24
 
25
  def check_dataset_and_get_config(dataset_id, uid):
26
  try:
27
- write_column_mapping(None, uid) # reset column mapping
28
  configs = datasets.get_dataset_config_names(dataset_id)
29
  return gr.Dropdown(configs, value=configs[0], visible=True)
30
  except Exception:
@@ -52,20 +52,17 @@ def write_column_mapping_to_config(
52
  )
53
  if labels is None:
54
  return
55
- labels = [*labels]
56
- all_mappings = read_column_mapping(uid)
57
 
58
- if all_mappings is None:
59
- all_mappings = dict()
60
 
61
  if "labels" not in all_mappings.keys():
62
  all_mappings["labels"] = dict()
63
  for i, label in enumerate(labels[:MAX_LABELS]):
64
  if label:
65
- all_mappings["labels"][label] = ds_labels[i]
66
  if "features" not in all_mappings.keys():
67
  all_mappings["features"] = dict()
68
- for i, feat in enumerate(labels[MAX_LABELS : (MAX_LABELS + MAX_FEATURES)]):
69
  if feat:
70
  # TODO: Substitute 'text' with more features for zero-shot
71
  all_mappings["features"]["text"] = feat
 
24
 
25
  def check_dataset_and_get_config(dataset_id, uid):
26
  try:
27
+ # write_column_mapping(None, uid) # reset column mapping
28
  configs = datasets.get_dataset_config_names(dataset_id)
29
  return gr.Dropdown(configs, value=configs[0], visible=True)
30
  except Exception:
 
52
  )
53
  if labels is None:
54
  return
 
 
55
 
56
+ all_mappings = dict()
 
57
 
58
  if "labels" not in all_mappings.keys():
59
  all_mappings["labels"] = dict()
60
  for i, label in enumerate(labels[:MAX_LABELS]):
61
  if label:
62
+ all_mappings["labels"][label] = ds_labels[i%len(ds_labels)]
63
  if "features" not in all_mappings.keys():
64
  all_mappings["features"] = dict()
65
+ for _, feat in enumerate(labels[MAX_LABELS : (MAX_LABELS + MAX_FEATURES)]):
66
  if feat:
67
  # TODO: Substitute 'text' with more features for zero-shot
68
  all_mappings["features"]["text"] = feat