Spaces:
Sleeping
Sleeping
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() |