File size: 12,187 Bytes
848090a
 
 
 
 
 
 
 
b63b62d
 
 
f556400
848090a
f556400
848090a
f556400
848090a
f556400
848090a
 
 
 
 
 
 
 
b63b62d
 
 
848090a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f556400
848090a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b63b62d
848090a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f556400
848090a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f556400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848090a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
from pymongo_get_database import MongoDBManager
from utils import process_markdown, save_answer, randomly_select_prompts, generate_unassisted_question

from experiment_details import problem_topics, problems_per_topic, writing_skills_questions
from data_storage import store_user_data

import gradio as gr

# mongo_manager = MongoDBManager()

def generate_questionnaire(all_results, completed_screen, mongo_manager):
    global dem_answers
    dem_answers = {}
    global usercap_answers
    usercap_answers = {}
    global reln_answers
    reln_answers = {}
    global pref_answers
    pref_answers = {}

    with gr.Column("Questionnaire", render=False, visible=False) as questionnaire:
        questionnaire_instr_md = process_markdown(False, 'instr_questionnaire.md')
        questionnaire_instr = gr.Markdown(value=questionnaire_instr_md)

        def finish_pref():
            all_results['System Output Preferences'] = pref_answers
            store_user_data(mongo_manager.user_id, "questionnaire", all_results)
            print(mongo_manager.user_id)
            mongo_manager.update_questionnaire_answers(all_results)
            return {
                pref: gr.update(visible=False),
                completed_screen: gr.update(visible=True),
                questionnaire_instr: gr.update(visible=False)
            }

        with gr.Column("System Output Preferences", render=True, visible=False) as pref:

            def save_results(question, answer, total_num_questions):
                pref_answers[question] = answer
                questions_answered = int(total_num_questions) == len(pref_answers)
                if questions_answered:
                    return str(pref_answers), questions_answered, gr.Button(interactive=True)
                else:
                    return str(pref_answers), questions_answered, gr.Button(interactive=False)

            q_num = 1
            pref_questions = writing_skills_questions['System Output Preferences']
            total_questions_len = str(len(pref_questions))

            with gr.Row(visible=False):
                radio_outputs = gr.Textbox(label="Choices")
                all_questions_answered = gr.Textbox(label="All Questions Answered")
            with gr.Row(render=False) as output_row:
                finish_pref_btn = gr.Button(
                    "Submit Questionnaire",
                    variant="primary",
                    interactive=False)
            with gr.Group():
                for q in pref_questions:
                    with gr.Row():
                        # Hidden textbox to hold the question value
                        question_input = gr.Textbox(value=q['Question'], visible=False)
                        total_num_questions = gr.Textbox(value=total_questions_len, visible=False)
                        single_question = gr.Radio(
                            choices=q['AnswerChoices'],
                            label=str(q_num) + '. ' + q['Question'],
                            interactive=True,
                            visible=True
                        )
                        # Use the hidden textbox as part of the inputs
                        single_question.change(
                            fn=save_results,
                            inputs=[question_input, single_question, total_num_questions],
                            outputs=[radio_outputs, all_questions_answered, finish_pref_btn]
                        )
                        q_num += 1
            output_row.render()
            finish_pref_btn.click(
                fn=finish_pref,
                inputs=[],
                outputs=[pref, completed_screen, questionnaire_instr]
            )

        def finish_reln():
            all_results['Relationship to System'] = reln_answers
            return {
                reln: gr.update(visible=False),
                pref: gr.update(visible=True)
            }

        with gr.Column("Relationship to System", render=True, visible=False) as reln:

            def save_results(question, answer, total_num_questions):
                reln_answers[question] = answer
                questions_answered = int(total_num_questions) == len(reln_answers)
                if questions_answered:
                    return str(reln_answers), questions_answered, gr.Button(interactive=True)
                else:
                    return str(reln_answers), questions_answered, gr.Button(interactive=False)

            q_num = 1
            reln_questions = writing_skills_questions['Relationship to System']
            total_questions_len = str(len(reln_questions))

            with gr.Row(visible=False):
                radio_outputs = gr.Textbox(label="Choices")
                all_questions_answered = gr.Textbox(label="All Questions Answered")
            with gr.Row(render=False) as output_row:
                finish_reln_btn = gr.Button(
                    "Next",
                    variant="primary",
                    interactive=False)
            with gr.Group():
                for q in reln_questions:
                    with gr.Row():
                        # Hidden textbox to hold the question value
                        question_input = gr.Textbox(value=q['Question'], visible=False)
                        total_num_questions = gr.Textbox(value=total_questions_len, visible=False)
                        single_question = gr.Radio(
                            choices=q['AnswerChoices'],
                            label=str(q_num) + '. ' + q['Question'],
                            interactive=True,
                            visible=True
                        )
                        # Use the hidden textbox as part of the inputs
                        single_question.change(
                            fn=save_results,
                            inputs=[question_input, single_question, total_num_questions],
                            outputs=[radio_outputs, all_questions_answered, finish_reln_btn]
                        )
                        q_num += 1
            output_row.render()
            finish_reln_btn.click(
                fn=finish_reln,
                inputs=[],
                outputs=[reln, pref]
            )

        def finish_usercap():
            all_results['User Capabilities'] = usercap_answers
            return {
                usercap: gr.update(visible=False),
                reln: gr.update(visible=True)
            }

        with gr.Column("User Capabilities", render=True, visible=False) as usercap:

            def save_results(question, answer, total_num_questions):
                usercap_answers[question] = answer
                questions_answered = int(total_num_questions) == len(usercap_answers)
                if questions_answered:
                    return str(usercap_answers), questions_answered, gr.Button(interactive=True)
                else:
                    return str(usercap_answers), questions_answered, gr.Button(interactive=False)

            q_num = 1
            usercap_questions = writing_skills_questions['User Capabilities']
            total_questions_len = str(len(usercap_questions))

            with gr.Row(visible=False):
                radio_outputs = gr.Textbox(label="Choices")
                all_questions_answered = gr.Textbox(label="All Questions Answered")
            with gr.Row(render=False) as output_row:
                finish_usercap_btn = gr.Button(
                    "Next",
                    variant="primary",
                    interactive=False)
            with gr.Group():
                for q in usercap_questions:
                    with gr.Row():
                        # Hidden textbox to hold the question value
                        question_input = gr.Textbox(value=q['Question'], visible=False)
                        total_num_questions = gr.Textbox(value=total_questions_len, visible=False)
                        single_question = gr.Radio(
                            choices=q['AnswerChoices'],
                            label=str(q_num) + '. ' + q['Question'],
                            interactive=True,
                            visible=True
                        )
                        # Use the hidden textbox as part of the inputs
                        single_question.change(
                            fn=save_results,
                            inputs=[question_input, single_question, total_num_questions],
                            outputs=[radio_outputs, all_questions_answered, finish_usercap_btn]
                        )
                        q_num += 1
            output_row.render()
            finish_usercap_btn.click(
                fn=finish_usercap,
                inputs=[],
                outputs=[usercap, reln]
            )

        def finish_dem():
            all_results['Demographic Details'] = dem_answers
            return {
                dem: gr.update(visible=False),
                usercap: gr.update(visible=True)
            }

        with gr.Column("Demographic", render = True, visible=False) as dem:

            def save_results(question, answer, total_num_questions):
                dem_answers[question] = answer
                questions_answered = int(total_num_questions) == len(dem_answers)
                if questions_answered:
                    return str(dem_answers), questions_answered, gr.Button(interactive=True)
                else:
                    return str(dem_answers), questions_answered, gr.Button(interactive=False)

            q_num = 1
            dem_questions = writing_skills_questions['Demographic Details']
            total_questions_len = str(len(dem_questions))

            with gr.Row(visible=False):
                radio_outputs = gr.Textbox(label="Choices")
                all_questions_answered = gr.Textbox(label="All Questions Answered")
            with gr.Row(render=False) as output_row:
                finish_dem_btn = gr.Button(
                    "Next",
                    variant="primary",
                    interactive=False)
            with gr.Group():
                for q in dem_questions:
                    with gr.Row():
                        # Hidden textbox to hold the question value
                        question_input = gr.Textbox(value=q['Question'], visible=False)
                        total_num_questions = gr.Textbox(value=total_questions_len, visible=False)
                        single_question = gr.Radio(
                            choices=q['AnswerChoices'],
                            label=str(q_num) + '. ' + q['Question'],
                            interactive=True,
                            visible=True
                        )
                        # Use the hidden textbox as part of the inputs
                        single_question.change(
                            fn=save_results,
                            inputs=[question_input, single_question, total_num_questions],
                            outputs=[radio_outputs, all_questions_answered, finish_dem_btn]
                        )
                        q_num += 1
            output_row.render()
            finish_dem_btn.click(
                fn=finish_dem,
                inputs=[],
                outputs=[dem, usercap]
            )

        def begin_questionnaire():
            global dem_answers
            dem_answers = {}
            global usercap_answers
            usercap_answers = {}
            global reln_answers
            reln_answers = {}
            global pref_answers
            pref_answers = {}
            return {
                welcome: gr.update(visible=False),
                dem: gr.update(visible=True)
            }
        with gr.Column("Welcome", render=True) as welcome:
            begin_questionnaire_btn = gr.Button(
                "Begin Questionnaire",
                variant="primary",
                interactive=True)
            begin_questionnaire_btn.click(
                fn=begin_questionnaire,
                inputs=[],
                outputs=[welcome, dem]
            )

    return questionnaire