Spaces:
Sleeping
Sleeping
File size: 2,640 Bytes
a3bf6d5 c98c5d7 a3bf6d5 c98c5d7 a3bf6d5 92933b9 a3bf6d5 92933b9 a3bf6d5 c98c5d7 a3bf6d5 c98c5d7 a3bf6d5 92933b9 c98c5d7 a3bf6d5 c98c5d7 92933b9 c98c5d7 92933b9 c98c5d7 a3bf6d5 c98c5d7 92933b9 c98c5d7 92933b9 a3bf6d5 c98c5d7 |
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 64 65 66 67 68 |
import gradio as gr
import pandas as pd
import random
USERS = ['user1', 'user2', 'user3']
df_per_user = {}
df = pd.read_csv("data.csv")
df['score'] = None
df['assignee'] = random.choices(USERS, k=len(df))
for u in USERS:
df_per_user[u] = df[df.assignee == u].to_dict('records')
with gr.Blocks() as demo:
dataset_df = {}
state = gr.State(value=-1)
with gr.Row():
gr.Markdown("# Distributed Evaluation Parallel π")
with gr.Row():
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():
with gr.Column():
gr.Markdown("## TODO")
todos = gr.DataFrame()
with gr.Column():
gr.Markdown("## DONE")
done = gr.DataFrame()
def prev_func(score, request: gr.Request):
df_dict = df_per_user[request.username]
state.value = max(state.value - 1, 0)
score = df_dict[state.value]['score']
gr.Info(f"{request.username}λ, μ΄ {len(df_dict)}κ° μ€μ {state.value + 1}λ²μ§Έ λ°μ΄ν°μ
λλ€.")
return [*update(request.username), score]
def next_func(score, request: gr.Request):
df_dict = df_per_user[request.username]
df_dict[state.value]['score'] = score
state.value = min(state.value + 1, len(df_dict) - 1)
score = df_dict[state.value]['score']
gr.Info(f"{request.username}λ, μ΄ {len(df_dict)}κ° μ€μ {state.value + 1}λ²μ§Έ λ°μ΄ν°μ
λλ€.")
return [*update(request.username), score]
def update(username):
df_dict = df_per_user[username]
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]
filename = f"done_{username}.csv"
done.to_csv(filename, index=False)
return q, g, p, todos, done, filename
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(concurrency_count=10)
demo.launch(auth=[(u, u) for u in USERS]) |