File size: 7,294 Bytes
6202874
40aaeab
9d9db50
8ce772a
 
407dc6a
 
a132742
7c6a50c
 
5b2eeff
407dc6a
 
c0ffcf0
 
a132742
f462dee
40aaeab
9d9db50
0aee0a2
3cda69c
40aaeab
6204dd5
 
 
5d7b55b
6204dd5
4132bd2
6204dd5
ca6769f
 
 
 
ccef0cf
ca6769f
6204dd5
fa382bb
40aaeab
6204dd5
 
9cbdd68
a132742
3b276b3
7510cad
ba8469c
4132bd2
ba8469c
8319c95
4132bd2
 
 
ccef0cf
ba8469c
b7ce205
4132bd2
8319c95
3b276b3
8319c95
b60cd75
4132bd2
3cda69c
6204dd5
077efe5
407dc6a
 
 
 
 
 
 
 
077efe5
407dc6a
 
 
 
 
 
 
 
 
 
 
3cda69c
2e8cc42
a132742
5b2eeff
 
 
 
 
 
a132742
40aaeab
5b2eeff
 
 
c0ffcf0
f595ced
5b2eeff
 
c0ffcf0
 
 
 
5b2eeff
 
54c4c7c
 
 
 
 
 
 
ae6f5c6
 
 
 
 
2e8cc42
5b2eeff
 
7c6a50c
21adc07
7c6a50c
 
5b2eeff
7c6a50c
21adc07
7c6a50c
 
6204dd5
 
 
fa382bb
6204dd5
9d9db50
6204dd5
 
 
40aaeab
6204dd5
9d9db50
407dc6a
c3aa782
6204dd5
0cb1968
6204dd5
9d9db50
7ca737f
67528be
7ca737f
 
d54eb8b
7ca737f
 
 
 
 
c3aa782
6204dd5
 
a132742
 
5b2eeff
 
a132742
 
 
 
 
a5ce95a
c0ffcf0
 
 
 
 
 
a5ce95a
 
 
 
 
c0ffcf0
a5ce95a
c0ffcf0
 
5b2eeff
c0ffcf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b2eeff
 
8ce772a
 
 
fa382bb
5d7b55b
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
# main.py
import gradio as gr
import logging

from app.ui.common import log_dropdown_choice
from app.ui.diagnoser_tab import build_diagnoser_tab
from app.ui.distractors_tab import build_distractors_tab
from app.ui.learning_objectives_tab import build_learning_objectives_tab
from app.ui.prompts_tab import build_prompts_tab
from app.ui.test_set_tab import build_test_set_tab
from app.ui.write_fluster_tab import build_write_fluster_tab
from chains.diagnoser.runner import run_diagnoser
from chains.distractors.runner import run_distractors
from chains.exercises.run_fluster_with_diagnosis import run_fluster_with_diagnosis
from chains.exercises.runner_without import run_fluster_no_diagnosis
from chains.learning_objectives_generator.runner import run_learning_objectives_generator
from utils.auth import login as auth_login

logger = logging.getLogger(__name__)



# -------------------------------
# Build the Gradio Interface
# -------------------------------
with gr.Blocks() as interface:
    # --- Login Page ---
    with gr.Column(visible=True, elem_id="login_page") as login_container:
        gr.Markdown("## 🔒 Please Login")
        password_input = gr.Textbox(
            label="Enter Password",
            type="password",
            placeholder="hunter2",
            container=True
        )
        login_button = gr.Button("Login")
        login_error = gr.Markdown(value="")

    # --- Main App (initially hidden) ---
    with gr.Column(visible=False, elem_id="main_app") as app_container:

        # --- Standardized Exercise/Study text Display (Initially Invisible Because it's empty) ---
        # A row for Title & the standardized text & copy button
        with gr.Row():
            with gr.Column(scale=3):
                gr.Markdown("")
            with gr.Column(scale=5):
                standardized_format_display = gr.Textbox(
                    info="",
                    label="",
                    show_label=False,
                    show_copy_button=True,
                    placeholder="will show most recent reformatting result",
                    lines=1,
                    max_lines=10,
                    interactive=False,
                    container=False
                )

        gr.Markdown("## Pick the tab for your task of choice")

        with gr.Tabs():
            # Build Diagnoser tab
            (model_choice_diagnose,
             exercise_format_diagnose,
             sampling_count_diagnose,
             diagnoser_input,
             diagnoser_button,
             diagnoser_responses
            ) = build_diagnoser_tab()

            # Build Distractors tab
            (model_choice_distractors_1,
             model_choice_distractors_2,
             model_choice_distractors_3,
             exercise_format_distractors,
             sampling_count_distractors,
             distractors_input,
             distractors_button,
             distractors_responses,
             intermediate_distractors_specification,
             final_distractors_specification,
             ) = build_distractors_tab()


            # Build Learning Objectives Generator tab
            (model_choice_LO_1,
             model_choice_LO_2,
             text_format,
             studytext_input,
             learning_objectives_button,
             [LO_box_0, LO_box_1, LO_box_2, LO_box_3]
             ) = build_learning_objectives_tab()

            # Build write_fluster tab
            (model_choice_fluster_1,
             model_choice_fluster_2,
             include_diagnosis,
             exercises_input,
             write_fluster_button,
             [fluster_box_0, fluster_box_1, fluster_box_2, fluster_box_3],
             diagnosis_box_1,
             diagnosis_box_3,
             fixes_box_1,
             fixes_box_3
             ) = build_write_fluster_tab()

            # 6 Empty separators (somehow scale=6 doesn't work)
            with gr.Tab("", visible=True):
                pass
            with gr.Tab("", visible=True):
                pass
            with gr.Tab("", visible=True):
                pass
            with gr.Tab("", visible=True):
                pass
            with gr.Tab("", visible=True):
                pass
            with gr.Tab("", visible=True):
                pass

            # Build Prompts tab
            (pipeline_choice,
             search_field_prompts,
             ) = build_prompts_tab()

            # Build Test Set tab
            (subset_choice,
             search_field_test_set,
             ) = build_test_set_tab()

    # -------------------------------
    # Set Up Interactions
    # -------------------------------
    # Login button interaction.
    login_button.click(
        fn=auth_login,
        inputs=[password_input],
        outputs=[login_container, app_container, login_error]
    )

    diagnoser_button.click(
        fn=run_diagnoser,
        inputs=[diagnoser_input, model_choice_diagnose, exercise_format_diagnose, sampling_count_diagnose],
        outputs=diagnoser_responses + [standardized_format_display],
    )

    distractors_button.click(
        fn=run_distractors,
        inputs=[
            distractors_input,  # user query
            model_choice_distractors_1,
            model_choice_distractors_2,
            model_choice_distractors_3,
            exercise_format_distractors,
            sampling_count_distractors,
            intermediate_distractors_specification,
            final_distractors_specification,
        ],
        outputs=distractors_responses + [standardized_format_display],
    )

    learning_objectives_button.click(
        fn=run_learning_objectives_generator,  # Our async generator
        inputs=[studytext_input, model_choice_LO_1, model_choice_LO_2, text_format],
        outputs=[LO_box_0, LO_box_1, LO_box_2, LO_box_3, standardized_format_display],
        queue=True,
        api_name=None,
        # or "stream=True" depending on your version of Gradio
    )

    async def fluster_pipeline_dispatch(
            user_input: str,
            model_1: str,
            model_2: str,
            include_diagnosis: bool
    ):
        if not include_diagnosis:
            generator = run_fluster_no_diagnosis(user_input, model_1, model_2)
            final_results = ["", "", "", ""]
            async for results in generator:
                final_results = results
            return (*final_results, "", "", "", "")
        else:
            return await run_fluster_with_diagnosis(user_input, model_1, model_2)


    write_fluster_button.click(
        fn=fluster_pipeline_dispatch,
        inputs=[
            exercises_input,
            model_choice_fluster_1,
            model_choice_fluster_2,
            include_diagnosis
        ],
        outputs=[
            fluster_box_0,  # track1
            fluster_box_1,  # track2
            fluster_box_2,  # track3
            fluster_box_3,  # track4
            diagnosis_box_1,
            diagnosis_box_3,
            fixes_box_1,
            fixes_box_3
        ],
        queue=True
    )

    pipeline_choice.change(fn=log_dropdown_choice, inputs=pipeline_choice, outputs=[])
    subset_choice.change(fn=log_dropdown_choice, inputs=subset_choice, outputs=[])

# Launch the app.
interface.launch()