File size: 2,373 Bytes
94bd001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import pandas as pd

with gr.Blocks() as demo:
    dataset_df = {}
    state = gr.State(value=0)
    with gr.Row():
        gr.Markdown("# Distributed Evaluation Parallel ๐Ÿ˜Ž")
    with gr.Row():
        file = gr.File(label="Upload a file")
        prev = gr.Button(value="Previous")
        next = gr.Button(value="Next")
        download = gr.File(label="Download a file")
    with gr.Row():
        with gr.Column():
            question = gr.Textbox(label="Question")
        with gr.Column():
            ground_truth = gr.Textbox(label="GT")
        with gr.Column():
            prediction = gr.Textbox(label="Prediction")
            score = gr.Radio(choices=["Incorrect", "Correct"], label="Score")
    with gr.Row():
        todos = gr.DataFrame()
        done = gr.DataFrame()
    

    def csv2df(file):
        df = pd.read_csv(file.name)
        df['score'] = None
        df_dict = df.to_dict('records')
        dataset_df.update(dict(df=df, df_dict=df_dict))
        return update()

    def prev_func(score):
        df_dict = dataset_df['df_dict']
        state.value = max(state.value - 1, 0)
        score = df_dict[state.value]['score']
        gr.Info(f"์ด {len(dataset_df['df'])}๊ฐœ ์ค‘์— {state.value + 1}๋ฒˆ์งธ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค.")
        return [*update(), score]
    
    def next_func(score):
        df_dict = dataset_df['df_dict']
        df_dict[state.value]['score'] = score
        state.value = min(state.value + 1, len(dataset_df['df']) - 1)
        score = df_dict[state.value]['score']
        gr.Info(f"์ด {len(dataset_df['df'])}๊ฐœ ์ค‘์— {state.value + 1}๋ฒˆ์งธ ๋ฐ์ดํ„ฐ์ž…๋‹ˆ๋‹ค.")
        return [*update(), score]

    def update():
        df_dict = dataset_df['df_dict']
        q = df_dict[state.value]['question']
        g = df_dict[state.value]['answer']
        p = df_dict[state.value]['prediction']
        df = pd.DataFrame(df_dict)
        todos = df[df.score.isna()]
        done = df[df.score.isna() == False]
        return q, g, p, todos, done, "data_backup.csv"
    file.upload(csv2df, file, [question, ground_truth, prediction, todos, done, download])
    prev.click(prev_func, [score], [question, ground_truth, prediction, todos, done, download, score])
    next.click(next_func, [score], [question, ground_truth, prediction, todos, done, download, score])

demo.queue()
demo.launch()