Spaces:
Sleeping
Sleeping
Update app.py
Browse files16 unmodified lines171819202021222324252627282930313233343556 unmodified lines9293948384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713812612712812913013113914014114214314414514614714814915015115215313313413513613713813914014114214315415515615715815916016116216314516416516614816716816917017117217317417517617717816 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):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 lines with gr.Blocks() as demo:
# Ideology Test drowndown with gr.Row(): ideology_test = gr.Dropdown( label="Ideology Test", choices=["Wahl-O-Mat", "Political Compass Test"], value="Wahl-O-Mat", # Default value filterable=False )
# Initialize 'political_statement' with default 'Wahl-O-Mat' values political_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' statements allow_custom_value = True )
# Link the dropdowns so that the political statement dropdown updates based on the selected ideology test ideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement) # Prompt manipulation dropdown with 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 value filterable=False )
direct_steering_option = gr.Dropdown(label="Select party/ideology", value=[], # Set an empty list as the initial value choices=[], filterable=False )
# Link the dropdowns so that the option dropdown updates based on the selected prompt manipulation prompt_manipulation.change(fn=update_direct_steering_options, inputs=prompt_manipulation, outputs=direct_steering_option) with 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 value filterable=False ) # Initialize 'political_statement' with default 'Wahl-O-Mat' values political_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' statements allow_custom_value = True ) # Link the dropdowns so that the political statement dropdown updates based on the selected ideology test ideology_test.change(fn=update_political_statement_options, inputs=ideology_test, outputs=political_statement) # Prompt manipulation dropdown with 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 value filterable=False ) direct_steering_option = gr.Dropdown(label="Select party/ideology", value=[], # Set an empty list as the initial value choices=[], filterable=False ) # Link the dropdowns so that the option dropdown updates based on the selected prompt manipulation prompt_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(): 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(): 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.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) # submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option], outputs=[output1, output2]) # Link settings to the predict function submit_btn.click( fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2, prompt_manipulation, direct_steering_option, ideology_test, political_statement], 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