Yoon-gu Hwang commited on
Commit
92933b9
·
1 Parent(s): 7d6c155

score 추가

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -7,10 +7,10 @@ with gr.Blocks() as demo:
7
  with gr.Row():
8
  gr.Markdown("# Distributed Evaluation Parallel 😎")
9
  with gr.Row():
10
- upload = gr.UploadButton(label="Upload a file")
11
  prev = gr.Button(value="Previous")
12
  next = gr.Button(value="Next")
13
- download = gr.Button(value="Download")
14
  with gr.Row():
15
  with gr.Column():
16
  question = gr.Textbox(label="Question")
@@ -18,7 +18,7 @@ with gr.Blocks() as demo:
18
  ground_truth = gr.Textbox(label="GT")
19
  with gr.Column():
20
  prediction = gr.Textbox(label="Prediction")
21
- score = gr.Radio(["Incorrect", "Correct"], label="Score")
22
  with gr.Row():
23
  todos = gr.DataFrame()
24
  done = gr.DataFrame()
@@ -26,25 +26,38 @@ with gr.Blocks() as demo:
26
 
27
  def csv2df(file):
28
  df = pd.read_csv(file.name)
29
- dataset_df.update(dict(df=df))
 
 
30
  return update()
31
 
32
- def prev_func():
 
33
  state.value = max(state.value - 1, 0)
34
- return update()
 
 
35
 
36
- def next_func():
 
 
37
  state.value = min(state.value + 1, len(dataset_df['df']) - 1)
38
- return update()
 
 
39
 
40
  def update():
41
- q = dataset_df['df'].question.to_list()[state.value]
42
- g = dataset_df['df'].answer.to_list()[state.value]
43
- p = dataset_df['df'].prediction.to_list()[state.value]
44
- return q, g, p, dataset_df['df'], dataset_df['df']
45
- upload.upload(csv2df, upload, [question, ground_truth, prediction, todos, done])
46
- prev.click(prev_func, None, [question, ground_truth, prediction, todos, done])
47
- next.click(next_func, None, [question, ground_truth, prediction, todos, done])
 
 
 
 
48
 
49
  demo.queue()
50
  demo.launch()
 
7
  with gr.Row():
8
  gr.Markdown("# Distributed Evaluation Parallel 😎")
9
  with gr.Row():
10
+ file = gr.File(label="Upload a file")
11
  prev = gr.Button(value="Previous")
12
  next = gr.Button(value="Next")
13
+ download = gr.File(label="Download a file")
14
  with gr.Row():
15
  with gr.Column():
16
  question = gr.Textbox(label="Question")
 
18
  ground_truth = gr.Textbox(label="GT")
19
  with gr.Column():
20
  prediction = gr.Textbox(label="Prediction")
21
+ score = gr.Radio(choices=["Incorrect", "Correct"], label="Score")
22
  with gr.Row():
23
  todos = gr.DataFrame()
24
  done = gr.DataFrame()
 
26
 
27
  def csv2df(file):
28
  df = pd.read_csv(file.name)
29
+ df['score'] = None
30
+ df_dict = df.to_dict('records')
31
+ dataset_df.update(dict(df=df, df_dict=df_dict))
32
  return update()
33
 
34
+ def prev_func(score):
35
+ df_dict = dataset_df['df_dict']
36
  state.value = max(state.value - 1, 0)
37
+ score = df_dict[state.value]['score']
38
+ gr.Info(f"총 {len(dataset_df['df'])}개 중에 {state.value + 1}번째 데이터입니다.")
39
+ return [*update(), score]
40
 
41
+ def next_func(score):
42
+ df_dict = dataset_df['df_dict']
43
+ df_dict[state.value]['score'] = score
44
  state.value = min(state.value + 1, len(dataset_df['df']) - 1)
45
+ score = df_dict[state.value]['score']
46
+ gr.Info(f"총 {len(dataset_df['df'])}개 중에 {state.value + 1}번째 데이터입니다.")
47
+ return [*update(), score]
48
 
49
  def update():
50
+ df_dict = dataset_df['df_dict']
51
+ q = df_dict[state.value]['question']
52
+ g = df_dict[state.value]['answer']
53
+ p = df_dict[state.value]['prediction']
54
+ df = pd.DataFrame(df_dict)
55
+ todos = df[df.score.isna()]
56
+ done = df[df.score.isna() == False]
57
+ return q, g, p, todos, done, "data_backup.csv"
58
+ file.upload(csv2df, file, [question, ground_truth, prediction, todos, done, download])
59
+ prev.click(prev_func, [score], [question, ground_truth, prediction, todos, done, download, score])
60
+ next.click(next_func, [score], [question, ground_truth, prediction, todos, done, download, score])
61
 
62
  demo.queue()
63
  demo.launch()