mojakob/usability
0
1import gradio as gr2import pandas as pd3import os4from urllib.parse import urlparse, parse_qs5 6# Function to process responses and store them7def process_feedback(ease, clarity, engagement, satisfaction, cognitive_load, comments, state, request: gr.Request):8 # Extract Prolific ID and Version from URL9 params = parse_qs(urlparse(request.url).query)10 prolific_id = params.get("PROLIFIC_PID", ["Unknown"])[0]11 version = params.get("VERSION", ["Unknown"])[0]12 13 # Prepare and save the data14 data = {15 "Prolific ID": prolific_id,16 "Assessment Version": version,17 "Ease of Use": ease,18 "Clarity of Instructions": clarity,19 "Engagement Level": engagement,20 "Satisfaction with Assessment": satisfaction,21 "Cognitive Load": cognitive_load,22 "Comments": comments23 }24 25 # Save to CSV26 file_name = "usability_feedback.csv"27 if not os.path.exists(file_name):28 pd.DataFrame([data]).to_csv(file_name, index=False)29 else:30 pd.DataFrame([data]).to_csv(file_name, mode="a", header=False, index=False)31 32 # Return confirmation and show the return button33 state["completed"] = True34 return (35 f"Thank you, participant {prolific_id} (Version {version})! Your feedback has been recorded.",36 gr.update(visible=True)37 )38 39# Function to redirect to Prolific40def redirect_to_prolific():41 return gr.update(js="window.location.href='https://app.prolific.com/submissions/complete?cc=CBQG85HO';")42 43# Gradio Interface44with gr.Blocks() as app:45 state = gr.State({"completed": False})46 47 # Instructions48 gr.Markdown("""49 Thank you for completing the assessment. Please answer the following questions on a scale from 1 (= "Not at all") to 10 (= "Very much").50 """)51 52 # Usability Questions (Mix of NASA-TLX and PSSUQ)53 ease = gr.Slider(label="How easy was it to complete the assessment?", minimum=1, maximum=10, step=1)54 clarity = gr.Slider(label="How clear were the instructions?", minimum=1, maximum=10, step=1)55 engagement = gr.Slider(label="How engaging was the assessment experience?", minimum=1, maximum=10, step=1)56 satisfaction = gr.Slider(label="How satisfied are you with this assessment?", minimum=1, maximum=10, step=1)57 cognitive_load = gr.Slider(label="How mentally demanding was the assessment?", minimum=1, maximum=10, step=1)58 comments = gr.Textbox(label="Additional Comments (Optional)", lines=4)59 60 # Submit button and output61 submit_button = gr.Button("Submit")62 output_message = gr.Markdown(visible=False)63 return_button = gr.Button("Return to Prolific", visible=False)64 65 # Submit Button Logic66 submit_button.click(67 fn=process_feedback,68 inputs=[ease, clarity, engagement, satisfaction, cognitive_load, comments, state],69 outputs=[output_message, return_button]70 )71 72 # Return to Prolific Logic73 return_button.click(74 fn=redirect_to_prolific,75 inputs=None,76 outputs=None77 )78 79# Launch the App80app.launch(share=True)