jost commited on
Commit
6fcc9fc
1 Parent(s): 56c74c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -62
app.py CHANGED
@@ -17,7 +17,19 @@ def load_json_data(filepath):
17
  pct_data = load_json_data('data/pct.json')
18
  wahl_o_mat_data = load_json_data('data/wahl-o-mat.json')
19
 
20
- def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_steering_option: None, ideology_test: None, political_statement: None):
 
 
 
 
 
 
 
 
 
 
 
 
21
  print("Ideology Test:", ideology_test)
22
  print("Political Statement Number:", political_statement)
23
 
@@ -80,74 +92,87 @@ def main():
80
  with gr.Blocks() as demo:
81
 
82
  # Ideology Test drowndown
83
- with gr.Row():
84
- ideology_test = gr.Dropdown(
85
- label="Ideology Test",
86
- choices=["Wahl-O-Mat", "Political Compass Test"],
87
- value="Wahl-O-Mat", # Default value
88
- filterable=False
89
- )
90
-
91
- # Initialize 'political_statement' with default 'Wahl-O-Mat' values
92
- political_statement_initial_choices = [f"{i+1}. {statement['text']}" for i, statement in enumerate(wahl_o_mat_data['statements'])]
93
- political_statement = gr.Dropdown(
94
- label="Political Statement",
95
- placeholder="Enter your own political statement here or select one..."
96
- choices=political_statement_initial_choices, # Set default to 'Wahl-O-Mat' statements
97
- allow_custom_value = True
98
- )
99
-
100
- # Link the dropdowns so that the political statement dropdown updates based on the selected ideology test
101
- ideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement)
102
-
103
- # Prompt manipulation dropdown
104
- with gr.Row():
105
- prompt_manipulation = gr.Dropdown(
106
- label="Prompt Manipulation",
107
- choices=[
108
- "None",
109
- "Impersonation (direct steering)",
110
- "Most similar RAG (indirect steering with related context)",
111
- "Random RAG (indirect steering with randomized context)"
112
- ],
113
- value="None", # default value
114
- filterable=False
115
- )
116
-
117
- direct_steering_option = gr.Dropdown(label="Select party/ideology",
118
- value=[], # Set an empty list as the initial value
119
- choices=[],
120
- filterable=False
121
- )
122
-
123
- # Link the dropdowns so that the option dropdown updates based on the selected prompt manipulation
124
- prompt_manipulation.change(fn=update_direct_steering_options, inputs=prompt_manipulation, outputs=direct_steering_option)
125
 
126
- with gr.Row():
127
- gr.Markdown("#### OR:")
128
-
129
-
130
- with gr.Row():
131
- user_input1 = gr.Textbox(label="Prompt", placeholder="Enter your own political statement here")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
- with gr.Row():
134
- api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")
135
- user_input = gr.Textbox(label="Prompt", placeholder="Enter your message here")
136
- model_selector1 = gr.Dropdown(label="Model 1", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
137
- model_selector2 = gr.Dropdown(label="Model 2", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
138
- submit_btn = gr.Button("Submit")
139
-
140
-
141
- with gr.Row():
142
- output1 = gr.Textbox(label="Model 1 Response")
143
- output2 = gr.Textbox(label="Model 2 Response")
144
 
145
- # submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option], outputs=[output1, output2])
146
  submit_btn.click(
147
  fn=predict,
148
- inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement],
149
  outputs=[output1, output2]
150
  )
 
 
 
 
 
 
151
  demo.launch()
152
 
153
  if __name__ == "__main__":
 
17
  pct_data = load_json_data('data/pct.json')
18
  wahl_o_mat_data = load_json_data('data/wahl-o-mat.json')
19
 
20
+ def predict(
21
+ api_key,
22
+ user_input,
23
+ model1,
24
+ model2,
25
+ prompt_manipulation,
26
+ direct_steering_option,
27
+ ideology_test,
28
+ political_statement,
29
+ temperature,
30
+ top_p
31
+ ):
32
+
33
  print("Ideology Test:", ideology_test)
34
  print("Political Statement Number:", political_statement)
35
 
 
92
  with gr.Blocks() as demo:
93
 
94
  # Ideology Test drowndown
95
+ with gr.Tab("App"):
96
+ with gr.Row():
97
+ ideology_test = gr.Dropdown(
98
+ label="Ideology Test",
99
+ choices=["Wahl-O-Mat", "Political Compass Test"],
100
+ value="Wahl-O-Mat", # Default value
101
+ filterable=False
102
+ )
103
+
104
+ # Initialize 'political_statement' with default 'Wahl-O-Mat' values
105
+ political_statement_initial_choices = [f"{i+1}. {statement['text']}" for i, statement in enumerate(wahl_o_mat_data['statements'])]
106
+ political_statement = gr.Dropdown(
107
+ label="Political Statement",
108
+ placeholder="Enter your own political statement here or select one...",
109
+ choices=political_statement_initial_choices, # Set default to 'Wahl-O-Mat' statements
110
+ allow_custom_value = True
111
+ )
112
+
113
+ # Link the dropdowns so that the political statement dropdown updates based on the selected ideology test
114
+ ideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
+ # Prompt manipulation dropdown
117
+ with gr.Row():
118
+ prompt_manipulation = gr.Dropdown(
119
+ label="Prompt Manipulation",
120
+ choices=[
121
+ "None",
122
+ "Impersonation (direct steering)",
123
+ "Most similar RAG (indirect steering with related context)",
124
+ "Random RAG (indirect steering with randomized context)"
125
+ ],
126
+ value="None", # default value
127
+ filterable=False
128
+ )
129
+
130
+ direct_steering_option = gr.Dropdown(label="Select party/ideology",
131
+ value=[], # Set an empty list as the initial value
132
+ choices=[],
133
+ filterable=False
134
+ )
135
+
136
+ # Link the dropdowns so that the option dropdown updates based on the selected prompt manipulation
137
+ prompt_manipulation.change(fn=update_direct_steering_options, inputs=prompt_manipulation, outputs=direct_steering_option)
138
+
139
+ with gr.Row():
140
+ gr.Markdown("#### OR:")
141
+
142
+
143
+ with gr.Row():
144
+ user_input1 = gr.Textbox(label="Prompt", placeholder="Enter your own political statement here")
145
+
146
+ with gr.Row():
147
+ api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")
148
+ user_input = gr.Textbox(label="Prompt", placeholder="Enter your message here")
149
+ model_selector1 = gr.Dropdown(label="Model 1", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
150
+ model_selector2 = gr.Dropdown(label="Model 2", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
151
+ submit_btn = gr.Button("Submit")
152
+
153
 
154
+ with gr.Row():
155
+ output1 = gr.Textbox(label="Model 1 Response")
156
+ output2 = gr.Textbox(label="Model 2 Response")
157
+
158
+ with gr.Tab("Settings"):
159
+ with gr.Column():
160
+ api_key_input = gr.Textbox(label="API Key", type="password")
161
+ temp_input = gr.Slider(minimum=0, maximum=1, step=0.01, label="Temperature", value=0.7)
162
+ top_p_input = gr.Slider(minimum=0, maximum=1, step=0.01, label="Top P", value=1)
 
 
163
 
164
+ # Link settings to the predict function
165
  submit_btn.click(
166
  fn=predict,
167
+ inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement, temp_input, top_p_input],
168
  outputs=[output1, output2]
169
  )
170
+ # submit_btn.click(
171
+ # fn=predict,
172
+ # inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement],
173
+ # outputs=[output1, output2]
174
+ # )
175
+
176
  demo.launch()
177
 
178
  if __name__ == "__main__":