Zekun Wu commited on
Commit
8cb54c2
1 Parent(s): a6a3f18
Files changed (1) hide show
  1. pages/1_Injection.py +16 -15
pages/1_Injection.py CHANGED
@@ -26,9 +26,9 @@ def check_password():
26
  def initialize_state():
27
  keys = ["model_submitted", "api_key", "endpoint_url", "deployment_name", "temperature", "max_tokens",
28
  "data_processed", "group_name", "occupation", "privilege_label", "protect_label", "num_run",
29
- "uploaded_file", "additional_charateristics"]
30
  defaults = [False, "", "https://safeguard-monitor.openai.azure.com/", "gpt35-1106", 0.0, 150, False, "Gender",
31
- "Programmer", "Male", "Female", 1, None, None]
32
  for key, default in zip(keys, defaults):
33
  if key not in st.session_state:
34
  st.session_state[key] = default
@@ -58,32 +58,33 @@ else:
58
  if st.sidebar.button("Submit Model Info"):
59
  st.session_state.model_submitted = True
60
 
61
- # Ensure experiment settings are only shown if model info is submitted
62
- if st.session_state.model_submitted:
 
 
 
 
 
63
 
64
- categories = ["HR", "DESIGNER", "INFORMATION-TECHNOLOGY", "TEACHER", "ADVOCATE", "BUSINESS-DEVELOPMENT",
65
- "HEALTHCARE", "FITNESS", "AGRICULTURE", "BPO", "SALES", "CONSULTANT", "DIGITAL-MEDIA",
66
- "AUTOMOBILE", "CHEF", "FINANCE", "APPAREL", "ENGINEERING", "ACCOUNTANT", "CONSTRUCTION",
67
- "PUBLIC-RELATIONS", "BANKING", "ARTS", "AVIATION"]
68
 
69
- st.session_state.occupation = st.selectbox("Occupation", options=categories, index=categories.index(
70
- st.session_state.occupation) if st.session_state.occupation in categories else 0)
71
 
72
  df = None
73
  file_options = st.radio("Choose file source:", ["Upload", "Example"])
74
  if file_options == "Example":
75
  #df = pd.read_csv("prompt_test.csv")
76
  df = pd.read_csv("resume.csv")
 
77
  else:
78
  st.session_state.uploaded_file = st.file_uploader("Choose a file")
79
  if st.session_state.uploaded_file is not None:
80
  data = StringIO(st.session_state.uploaded_file.getvalue().decode("utf-8"))
81
  df = pd.read_csv(data)
82
  if df is not None:
83
- if file_options == "Example":
84
- st.write('Data:',df[df["Occupation"] == st.session_state.occupation])
85
- else:
86
- st.write('Data:', df)
87
 
88
  # Button to add a new row
89
 
@@ -109,7 +110,7 @@ else:
109
  # Process data and display results
110
  with st.spinner('Processing data...'):
111
  parameters = {"temperature": st.session_state.temperature, "max_tokens": st.session_state.max_tokens}
112
- preprocessed_df = process_scores_multiple(df[df["Occupation"] == st.session_state.occupation], st.session_state.num_run, parameters, st.session_state.privilege_label,st.session_state.protect_label, agent, st.session_state.group_name,st.session_state.occupation,st.session_state.additional_charateristics)
113
  st.session_state.data_processed = True # Mark as processed
114
 
115
  st.write('Processed Data:', preprocessed_df)
 
26
  def initialize_state():
27
  keys = ["model_submitted", "api_key", "endpoint_url", "deployment_name", "temperature", "max_tokens",
28
  "data_processed", "group_name", "occupation", "privilege_label", "protect_label", "num_run",
29
+ "uploaded_file", "additional_charateristics", "occupation_submitted"]
30
  defaults = [False, "", "https://safeguard-monitor.openai.azure.com/", "gpt35-1106", 0.0, 150, False, "Gender",
31
+ "Programmer", "Male", "Female", 1, None, None, False]
32
  for key, default in zip(keys, defaults):
33
  if key not in st.session_state:
34
  st.session_state[key] = default
 
58
  if st.sidebar.button("Submit Model Info"):
59
  st.session_state.model_submitted = True
60
 
61
+ categories = ["HR", "DESIGNER", "INFORMATION-TECHNOLOGY", "TEACHER", "ADVOCATE", "BUSINESS-DEVELOPMENT",
62
+ "HEALTHCARE", "FITNESS", "AGRICULTURE", "BPO", "SALES", "CONSULTANT", "DIGITAL-MEDIA",
63
+ "AUTOMOBILE", "CHEF", "FINANCE", "APPAREL", "ENGINEERING", "ACCOUNTANT", "CONSTRUCTION",
64
+ "PUBLIC-RELATIONS", "BANKING", "ARTS", "AVIATION"]
65
+
66
+ st.session_state.occupation = st.selectbox("Occupation", options=categories, index=categories.index(
67
+ st.session_state.occupation) if st.session_state.occupation in categories else 0)
68
 
69
+ if st.button("Submit Occupation Selection"):
70
+ st.session_state.occupation_submitted = True
 
 
71
 
72
+ # Ensure experiment settings are only shown if model info is submitted
73
+ if st.session_state.model_submitted and st.session_state.occupation_submitted:
74
 
75
  df = None
76
  file_options = st.radio("Choose file source:", ["Upload", "Example"])
77
  if file_options == "Example":
78
  #df = pd.read_csv("prompt_test.csv")
79
  df = pd.read_csv("resume.csv")
80
+ df = df[df["Occupation"] == st.session_state.occupation]
81
  else:
82
  st.session_state.uploaded_file = st.file_uploader("Choose a file")
83
  if st.session_state.uploaded_file is not None:
84
  data = StringIO(st.session_state.uploaded_file.getvalue().decode("utf-8"))
85
  df = pd.read_csv(data)
86
  if df is not None:
87
+ st.write('Data:', df)
 
 
 
88
 
89
  # Button to add a new row
90
 
 
110
  # Process data and display results
111
  with st.spinner('Processing data...'):
112
  parameters = {"temperature": st.session_state.temperature, "max_tokens": st.session_state.max_tokens}
113
+ preprocessed_df = process_scores_multiple(df, st.session_state.num_run, parameters, st.session_state.privilege_label,st.session_state.protect_label, agent, st.session_state.group_name,st.session_state.occupation,st.session_state.additional_charateristics)
114
  st.session_state.data_processed = True # Mark as processed
115
 
116
  st.write('Processed Data:', preprocessed_df)