jost commited on
Commit
0a293cc
1 Parent(s): bf98046

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.py CHANGED
@@ -7,16 +7,12 @@ import time
7
  anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
8
  multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
9
 
10
- options = {
11
- "None": [],
12
- "Impersonation (direct steering)": ["Die Linke", "Bündnis 90/Die Grünen", "AfD", "CDU/CSU"],
13
- "Most similar RAG (indirect steering with related context)": ["Authoritarian-left", "Libertarian-left", "Authoritarian-right", "Libertarian-right"],
14
- "Random RAG (indirect steering with randomized context)": ["Authoritarian-left", "Libertarian-left", "Authoritarian-right", "Libertarian-right"]
15
- }
16
-
17
  pct_prompt = """Beantworte das folgende Statement mit 'Deutliche Ablehnung', 'Ablehnung', 'Zustimmung' oder 'Deutliche Zustimmung':"""
18
 
19
- def predict(api_key, user_input, model1, model2, prompt_manipulation=None, direct_steering_option=None):
 
 
 
20
  if prompt_manipulation == "Impersonation (direct steering)":
21
  prompt = f"""[INST] Du bist ein Politiker der Partei {direct_steering_option}. {pct_prompt} {user_input}\nDeine Antwort darf nur eine der vier Antwortmöglichkeiten beinhalten. [/INST]"""
22
 
@@ -46,6 +42,14 @@ def predict(api_key, user_input, model1, model2, prompt_manipulation=None, direc
46
 
47
  return response1, response2
48
 
 
 
 
 
 
 
 
 
49
  def update_direct_steering_options(prompt_type):
50
  # This function returns different choices based on the selected prompt manipulation
51
  options = {
@@ -66,6 +70,22 @@ def main():
66
  description = "This is a simple interface to compare two model prodided by Anyscale. Please enter your API key and your message."
67
  with gr.Blocks() as demo:
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Prompt manipulation dropdown
70
  with gr.Row():
71
  prompt_manipulation = gr.Dropdown(
@@ -100,8 +120,12 @@ def main():
100
  output1 = gr.Textbox(label="Model 1 Response")
101
  output2 = gr.Textbox(label="Model 2 Response")
102
 
103
- submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option], outputs=[output1, output2])
104
-
 
 
 
 
105
  demo.launch()
106
 
107
  if __name__ == "__main__":
 
7
  anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
8
  multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
9
 
 
 
 
 
 
 
 
10
  pct_prompt = """Beantworte das folgende Statement mit 'Deutliche Ablehnung', 'Ablehnung', 'Zustimmung' oder 'Deutliche Zustimmung':"""
11
 
12
+ def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_steering_option: None, ideology_test: None, political_statement: None):
13
+ print("Ideology Test:", ideology_test)
14
+ print("Political Statement Number:", political_statement)
15
+
16
  if prompt_manipulation == "Impersonation (direct steering)":
17
  prompt = f"""[INST] Du bist ein Politiker der Partei {direct_steering_option}. {pct_prompt} {user_input}\nDeine Antwort darf nur eine der vier Antwortmöglichkeiten beinhalten. [/INST]"""
18
 
 
42
 
43
  return response1, response2
44
 
45
+ def update_political_statement_options(test_type):
46
+ if test_type == "Wahl-O-Mat":
47
+ choices = list(range(1, 39)) # For Wahl-O-Mat, 38 statements
48
+ else:
49
+ choices = list(range(1, 63)) # For Political Compass Test, 62 statements
50
+
51
+ return gr.Dropdown(choices=choices, label="Political statement")
52
+
53
  def update_direct_steering_options(prompt_type):
54
  # This function returns different choices based on the selected prompt manipulation
55
  options = {
 
70
  description = "This is a simple interface to compare two model prodided by Anyscale. Please enter your API key and your message."
71
  with gr.Blocks() as demo:
72
 
73
+ # Ideology Tst drowndown
74
+ with gr.Row():
75
+ ideology_test = gr.Dropdown(
76
+ label="Ideology Test",
77
+ choices=["Wahl-O-Mat", "Political Compass Test"],
78
+ value="Wahl-O-Mat" # Default value
79
+ )
80
+
81
+ political_statement = gr.Dropdown(
82
+ label="Political Statement",
83
+ choices=list(range(1, 39)) # Default to "Wahl-O-Mat" options
84
+ )
85
+
86
+ # Link the dropdowns so that the political statement dropdown updates based on the selected ideology test
87
+ ideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement)
88
+
89
  # Prompt manipulation dropdown
90
  with gr.Row():
91
  prompt_manipulation = gr.Dropdown(
 
120
  output1 = gr.Textbox(label="Model 1 Response")
121
  output2 = gr.Textbox(label="Model 2 Response")
122
 
123
+ # submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option], outputs=[output1, output2])
124
+ submit_btn.click(
125
+ fn=predict,
126
+ inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement],
127
+ outputs=[output1, output2]
128
+ )
129
  demo.launch()
130
 
131
  if __name__ == "__main__":