| import gradio as gr |
| import pandas as pd |
| import random |
|
|
|
|
| MODELS = ['falcon', 'gpt4all-j', 'llama2', 'mistralai', 'gpt-3.5-turbo', |
| 'vicuna', 'wizardlm', 'zephyr'] |
| MAX_ID = 2140 |
|
|
|
|
| def read_implicit_edos(path_to_implicit_edos='./data/edos_implicit.csv'): |
| return pd.read_csv(path_to_implicit_edos) |
|
|
|
|
| def random_id(max_int=MAX_ID): |
| return random.randint(0, max_int - 1) |
|
|
|
|
| def interact(implicit_data, m, i): |
| i = random_id(MAX_ID) if int(i) < 0 or int(i) >= MAX_ID else int(i) |
| m = 'refined_arguments' if m == 'gpt-3.5-turbo' else m |
| gen = pd.read_csv('./generations/' + m + '.csv') |
| return implicit_data['text'][i], gen['for'][i], gen['against'][i] |
|
|
|
|
| if __name__ == "__main__": |
| with gr.Blocks() as demo: |
| raw_data = gr.DataFrame(read_implicit_edos(), visible=False) |
|
|
| gr.Markdown("Demo") |
|
|
| with gr.Row(): |
| model = gr.Dropdown(label='Choose your LLM', choices=MODELS, value=MODELS[4]) |
| idx = gr.Number(value=-1, label="Sentence ID", precision=0) |
| button = gr.Button("Generate") |
| sentence = gr.Textbox(label='Context sentences') |
|
|
| with gr.Row(): |
| argument_for = gr.Textbox(label="Why sexist?", scale=1) |
| argument_against = gr.Textbox(label="Why non-sexist?", scale=1) |
|
|
| button.click( |
| fn=interact, |
| inputs=[raw_data, model, idx], |
| outputs=[sentence, argument_for, argument_against] |
| ) |
|
|
| demo.launch(share=True) |
|
|