File size: 2,874 Bytes
7d96992
 
 
beb6bae
314b49d
 
 
beb6bae
987f2a7
314b49d
987f2a7
314b49d
987f2a7
 
 
 
314b49d
987f2a7
 
 
314b49d
 
987f2a7
 
 
 
 
 
314b49d
987f2a7
 
314b49d
ae32083
987f2a7
 
314b49d
 
 
 
 
 
 
 
df570d0
314b49d
 
 
 
 
 
ae32083
987f2a7
ae32083
987f2a7
 
314b49d
 
 
987f2a7
 
 
 
314b49d
 
 
2b83ad7
987f2a7
ae32083
987f2a7
7d96992
4351029
2b83ad7
 
 
 
 
 
 
 
 
643c3a3
2b83ad7
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
# coding: utf-8

import json
import streamlit as st
from src.caller import OpenAI_Caller
from src.committee import Committee
from datasets import load_dataset

st.image('./img/meeting.psd')

st.header("Committee")

domains = st.multiselect(
    "Let's nominate committee members!",
    ["Age", "Disability Status", "Gender Identity", "Nationality", "Physical Appearance", "Race Ethnicity", "Religion", "Socioeconomic Status", "Sexual Orientation"],
    ["Age", "Nationality", "Religion"])

with st.spinner('Initializing committee members...'):
    committee_dict = {
        "chair": {
            "model_caller": OpenAI_Caller('gpt-4-1106-preview')
        },
        "member": [
            {"bias_type": domain, "model_caller": OpenAI_Caller('gpt-4-1106-preview')} for domain in domains
        ]
    }
with st.spinner('Initializing the committee...'):
    committee = Committee(committee_dict=committee_dict)

with st.spinner('Loding the BBQ datasets...'):
    dataset = load_dataset("Elfsong/BBQ")

category = st.selectbox("Which topic you are going to deliberate?", dataset.keys())
# instance_id = st.number_input("Ok, which one?", min_value=0, max_value=len(dataset[category]))
raw_instance = dataset[category][0]

instance = {
    "context": raw_instance['context'],
    "question": raw_instance['question'],
    "ans0": raw_instance['ans0'],
    "ans1": raw_instance['ans1'],
    "ans2": raw_instance['ans2'],
}
st.text("Here is an example, you can change the content on the fly!")
instance = st.data_editor(instance)

# Propose
st.header("Propose")
proposals = list()
for member in committee.members:
    with st.spinner(f'Member who concerns **{member.bias_type}** is proposing...'):
        proposal = member.propose(instance)
        st.subheader(f"Proposal from Member who concerns **{member.bias_type}**:")
        st.markdown(proposal)
        proposals += [proposal]

# Craft Motion
st.header("Motion")
with st.spinner(f'Chair is crafting a motion...'):
    motion = committee.chair.craft_motion(proposals, instance)
    st.subheader(f"Motion from the Chair:")
    st.markdown(motion)

# Vote
st.header("Vote")
vote_results = list()
for member in committee.members:
    with st.spinner(f'Member who concerns **{member.bias_type}** is voting...'):
        vote_result = member.vote(motion, instance)
        vote_result = json.loads(vote_result)
        vote_results += [True if vote_result['decision'] != "Veto" else False]
        vote_map = {
            "Pass": "Pass βœ…",
            "Veto": "Veto 🚫",
            "Abstain": "Abstain 😴"
        }
        st.subheader(f"Member who concerns **{member.bias_type}** votes: {vote_map[vote_result['decision']]}")
        
# Final Decision
st.header("Final Decision")
st.text(f'Given the voting result, the motion has been ' + "Passed βœ…" if all(vote_results) else "Rejected" + "! 🚫")
st.balloons()