Spaces:
Sleeping
Sleeping
Update app.py
Browse files16 unmodified lines1718192021222356 unmodified lines808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215316 unmodified linespct_data = load_json_data('data/pct.json')wahl_o_mat_data = load_json_data('data/wahl-o-mat.json')def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_steering_option: None, ideology_test: None, political_statement: None):print("Ideology Test:", ideology_test)print("Political Statement Number:", political_statement)56 unmodified lineswith gr.Blocks() as demo:# Ideology Test drowndownwith gr.Row():ideology_test = gr.Dropdown(label="Ideology Test",choices=["Wahl-O-Mat", "Political Compass Test"],value="Wahl-O-Mat", # Default valuefilterable=False)# Initialize 'political_statement' with default 'Wahl-O-Mat' valuespolitical_statement_initial_choices = [f"{i+1}. {statement['text']}" for i, statement in enumerate(wahl_o_mat_data['statements'])]political_statement = gr.Dropdown(label="Political Statement",placeholder="Enter your own political statement here or select one..."choices=political_statement_initial_choices, # Set default to 'Wahl-O-Mat' statementsallow_custom_value = True)# Link the dropdowns so that the political statement dropdown updates based on the selected ideology testideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement)# Prompt manipulation dropdownwith gr.Row():prompt_manipulation = gr.Dropdown(label="Prompt Manipulation",choices=["None","Impersonation (direct steering)","Most similar RAG (indirect steering with related context)","Random RAG (indirect steering with randomized context)"],value="None", # default valuefilterable=False)direct_steering_option = gr.Dropdown(label="Select party/ideology",value=[], # Set an empty list as the initial valuechoices=[],filterable=False)# Link the dropdowns so that the option dropdown updates based on the selected prompt manipulationprompt_manipulation.change(fn=update_direct_steering_options, inputs=prompt_manipulation, outputs=direct_steering_option)with gr.Row():gr.Markdown("#### OR:")with gr.Row():user_input1 = gr.Textbox(label="Prompt", placeholder="Enter your own political statement here")with gr.Row():api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")user_input = gr.Textbox(label="Prompt", placeholder="Enter your message here")model_selector1 = gr.Dropdown(label="Model 1", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])model_selector2 = gr.Dropdown(label="Model 2", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])submit_btn = gr.Button("Submit")with gr.Row():output1 = gr.Textbox(label="Model 1 Response")output2 = gr.Textbox(label="Model 2 Response")# submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option], outputs=[output1, output2])submit_btn.click(fn=predict,inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement],outputs=[output1, output2])demo.launch()if __name__ == "__main__":16 unmodified lines1718192021222324252627282930313233343556 unmodified lines929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717816 unmodified linespct_data = load_json_data('data/pct.json')wahl_o_mat_data = load_json_data('data/wahl-o-mat.json')def predict(api_key,user_input,model1,model2,prompt_manipulation,direct_steering_option,ideology_test,political_statement,temperature,top_p):print("Ideology Test:", ideology_test)print("Political Statement Number:", political_statement)56 unmodified lineswith gr.Blocks() as demo:# Ideology Test drowndownwith gr.Tab("App"):with gr.Row():ideology_test = gr.Dropdown(label="Ideology Test",choices=["Wahl-O-Mat", "Political Compass Test"],value="Wahl-O-Mat", # Default valuefilterable=False)# Initialize 'political_statement' with default 'Wahl-O-Mat' valuespolitical_statement_initial_choices = [f"{i+1}. {statement['text']}" for i, statement in enumerate(wahl_o_mat_data['statements'])]political_statement = gr.Dropdown(label="Political Statement",placeholder="Enter your own political statement here or select one...",choices=political_statement_initial_choices, # Set default to 'Wahl-O-Mat' statementsallow_custom_value = True)# Link the dropdowns so that the political statement dropdown updates based on the selected ideology testideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement)# Prompt manipulation dropdownwith gr.Row():prompt_manipulation = gr.Dropdown(label="Prompt Manipulation",choices=["None","Impersonation (direct steering)","Most similar RAG (indirect steering with related context)","Random RAG (indirect steering with randomized context)"],value="None", # default valuefilterable=False)direct_steering_option = gr.Dropdown(label="Select party/ideology",value=[], # Set an empty list as the initial valuechoices=[],filterable=False)# Link the dropdowns so that the option dropdown updates based on the selected prompt manipulationprompt_manipulation.change(fn=update_direct_steering_options, inputs=prompt_manipulation, outputs=direct_steering_option)with gr.Row():gr.Markdown("#### OR:")with gr.Row():user_input1 = gr.Textbox(label="Prompt", placeholder="Enter your own political statement here")with gr.Row():api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")user_input = gr.Textbox(label="Prompt", placeholder="Enter your message here")model_selector1 = gr.Dropdown(label="Model 1", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])model_selector2 = gr.Dropdown(label="Model 2", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])submit_btn = gr.Button("Submit")with gr.Row():output1 = gr.Textbox(label="Model 1 Response")output2 = gr.Textbox(label="Model 2 Response")with gr.Tab("Settings"):with gr.Column():api_key_input = gr.Textbox(label="API Key", type="password")temp_input = gr.Slider(minimum=0, maximum=1, step=0.01, label="Temperature", value=0.7)top_p_input = gr.Slider(minimum=0, maximum=1, step=0.01, label="Top P", value=1)# Link settings to the predict functionsubmit_btn.click(fn=predict,inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement, temp_input, top_p_input],outputs=[output1, output2])# submit_btn.click(# fn=predict,# inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement],# outputs=[output1, output2]# )demo.launch()if __name__ == "__main__":
app.py+87-62