Spaces:
Running
Running
Yoon-gu Hwang
commited on
Commit
β’
94bd001
1
Parent(s):
95257b5
add app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
dataset_df = {}
|
6 |
+
state = gr.State(value=0)
|
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")
|
17 |
+
with gr.Column():
|
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()
|
25 |
+
|
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()
|