Spaces:
Sleeping
Sleeping
File size: 3,953 Bytes
bb3c194 d2fca6f bb3c194 |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import gradio as gr
import pandas as pd
import os
from utils import construct_dataframe, MODELS, get_scores
HF_TOKEN = os.getenv("HF_TOKEN")
DATAFRAME: pd.DataFrame = construct_dataframe()
MAX_LINES = 500
MIN_LINES = 10
def get_from_question_id_turn_2(model, question_id: int):
new = DATAFRAME.loc[question_id]
new = new[new["turn"] == 1]
new = new[new["model"] == model]
prompt_lighteval = new["prompt"].values[0]
response_lighteval = new["response"].values[0]
judgement_prompt_lighteval = new["judgement_prompt"].values[0]
judgement_lighteval = new["judgment"].values[0]
score_lighteval = new["score"].values[0]
return prompt_lighteval, response_lighteval, judgement_prompt_lighteval[1]["content"], judgement_lighteval, score_lighteval
def get_from_question_id_turn_1(model, question_id: int):
new = DATAFRAME.loc[question_id]
new = new[new["turn"] == 0]
new = new[new["model"] == model]
prompt_lighteval = new["prompt"].values[0]
response_lighteval = new["response"].values[0]
judgement_prompt_lighteval = new["judgement_prompt"].values[0]
judgement_lighteval = new["judgment"].values[0]
score_lighteval = new["score"].values[0]
return prompt_lighteval, response_lighteval, judgement_prompt_lighteval[1]["content"], judgement_lighteval, score_lighteval
with gr.Blocks() as demo:
with gr.Row():
model = gr.Dropdown([model.split("__")[1] for model in MODELS], label="Model")
index = gr.Dropdown(set(DATAFRAME.index.values.tolist()), label="Index", value=DATAFRAME.index.values.tolist()[0])
with gr.Row():
gr.DataFrame(get_scores(DATAFRAME).reset_index(), interactive=False, )
with gr.Row():
with gr.Column():
gr.Markdown("## Turn 1")
score_lighteval = gr.Number(label="Score", interactive=False)
prompt_lighteval = gr.Textbox(
label="Prompt", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES
)
response_lighteval = gr.Textbox(label="Response", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
judgement_prompt_lighteval = gr.Textbox(label="Judgement Prompt", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
judgement_lighteval = gr.Textbox(label="Judgement", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
with gr.Column():
gr.Markdown("## Turn 2")
score_lighteval_2 = gr.Number(label="Score", interactive=False)
prompt_lighteval_2 = gr.Textbox(
label="Prompt", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES
)
response_lighteval_2 = gr.Textbox(label="Response", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
judgement_prompt_lighteval_2 = gr.Textbox(label="Judgement Prompt", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
judgement_lighteval_2 = gr.Textbox(label="Judgement", interactive=False, max_lines=MAX_LINES, lines=MIN_LINES)
index.change(
fn=get_from_question_id_turn_1,
inputs=[model, index],
outputs=[prompt_lighteval, response_lighteval, judgement_prompt_lighteval, judgement_lighteval, score_lighteval],
)
index.change(
fn=get_from_question_id_turn_2,
inputs=[model, index],
outputs=[prompt_lighteval_2, response_lighteval_2, judgement_prompt_lighteval_2, judgement_lighteval_2, score_lighteval_2],
)
model.change(
fn=get_from_question_id_turn_2,
inputs=[model, index],
outputs=[prompt_lighteval_2, response_lighteval_2, judgement_prompt_lighteval_2, judgement_lighteval_2, score_lighteval_2],
)
model.change(
fn=get_from_question_id_turn_1,
inputs=[model, index],
outputs=[prompt_lighteval, response_lighteval, judgement_prompt_lighteval, judgement_lighteval, score_lighteval,],
)
demo.launch()
|