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