5 output boxes
Browse files
app.py
CHANGED
|
@@ -54,8 +54,8 @@ async def run_chain(chain_name: str, input_variables: dict, selected_model: str)
|
|
| 54 |
return f"Error: {e}"
|
| 55 |
|
| 56 |
# Async wrappers for each chain.
|
| 57 |
-
async def run_diagnoser(user_query: str, chosen_model: str, exercise_format: str, sampling_count: str) ->
|
| 58 |
-
num_samples = int(sampling_count)
|
| 59 |
# Fetch the DiagnoserChain configuration.
|
| 60 |
config = chain_configs["diagnoser"]
|
| 61 |
|
|
@@ -72,15 +72,10 @@ async def run_diagnoser(user_query: str, chosen_model: str, exercise_format: str
|
|
| 72 |
for i in range(num_samples):
|
| 73 |
response = await chain_instance.run(user_query, exercise_format)
|
| 74 |
responses.append(response)
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
for i, resp in enumerate(responses)
|
| 80 |
-
]
|
| 81 |
-
# Return an update for the output column with these new children.
|
| 82 |
-
return gr.Column.update(children=output_components)
|
| 83 |
-
|
| 84 |
|
| 85 |
async def run_distractors(user_query: str, model_choice: str) -> str:
|
| 86 |
return await run_chain("distractors", {"user_query": user_query}, model_choice)
|
|
@@ -115,7 +110,7 @@ with gr.Blocks() as demo:
|
|
| 115 |
interactive=True,
|
| 116 |
)
|
| 117 |
sampling_count = gr.Dropdown(
|
| 118 |
-
choices=["1", "2
|
| 119 |
value="1",
|
| 120 |
label="Sampling Count π§",
|
| 121 |
interactive=True,
|
|
@@ -140,8 +135,11 @@ with gr.Blocks() as demo:
|
|
| 140 |
)
|
| 141 |
diagnoser_input = gr.Textbox(label="Enter exercise(s) in any format", placeholder="Exercise body: <mc:exercise xmlns:mc= ...")
|
| 142 |
diagnoser_button = gr.Button("Submit")
|
| 143 |
-
gr.
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
| 145 |
with gr.TabItem("π€ Generate distractors"):
|
| 146 |
# Insert an HTML info icon with a tooltip at the top of the tab content.
|
| 147 |
gr.HTML(
|
|
@@ -186,8 +184,15 @@ with gr.Blocks() as demo:
|
|
| 186 |
diagnoser_button.click(
|
| 187 |
fn=run_diagnoser,
|
| 188 |
inputs=[diagnoser_input, model_choice, exercise_format, sampling_count],
|
| 189 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
)
|
|
|
|
| 191 |
distractors_button.click(
|
| 192 |
fn=run_distractors,
|
| 193 |
inputs=[distractors_input, model_choice, exercise_format, sampling_count],
|
|
|
|
| 54 |
return f"Error: {e}"
|
| 55 |
|
| 56 |
# Async wrappers for each chain.
|
| 57 |
+
async def run_diagnoser(user_query: str, chosen_model: str, exercise_format: str, sampling_count: str) -> tuple:
|
| 58 |
+
num_samples = int("".join(filter(str.isdigit, sampling_count)))
|
| 59 |
# Fetch the DiagnoserChain configuration.
|
| 60 |
config = chain_configs["diagnoser"]
|
| 61 |
|
|
|
|
| 72 |
for i in range(num_samples):
|
| 73 |
response = await chain_instance.run(user_query, exercise_format)
|
| 74 |
responses.append(response)
|
| 75 |
+
# Fill missing responses (if any) up to 5 outputs.
|
| 76 |
+
all_responses = responses + [""] * (5 - len(responses))
|
| 77 |
+
# Return a tuple of exactly 5 responses.
|
| 78 |
+
return tuple(all_responses)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
async def run_distractors(user_query: str, model_choice: str) -> str:
|
| 81 |
return await run_chain("distractors", {"user_query": user_query}, model_choice)
|
|
|
|
| 110 |
interactive=True,
|
| 111 |
)
|
| 112 |
sampling_count = gr.Dropdown(
|
| 113 |
+
choices=["1", "2", "3", "4", "5"],
|
| 114 |
value="1",
|
| 115 |
label="Sampling Count π§",
|
| 116 |
interactive=True,
|
|
|
|
| 135 |
)
|
| 136 |
diagnoser_input = gr.Textbox(label="Enter exercise(s) in any format", placeholder="Exercise body: <mc:exercise xmlns:mc= ...")
|
| 137 |
diagnoser_button = gr.Button("Submit")
|
| 138 |
+
diagnoser_response_1 = gr.Textbox(label="Response 1", interactive=False)
|
| 139 |
+
diagnoser_response_2 = gr.Textbox(label="Response 2", interactive=False)
|
| 140 |
+
diagnoser_response_3 = gr.Textbox(label="Response 3", interactive=False)
|
| 141 |
+
diagnoser_response_4 = gr.Textbox(label="Response 4", interactive=False)
|
| 142 |
+
diagnoser_response_5 = gr.Textbox(label="Response 5", interactive=False)
|
| 143 |
with gr.TabItem("π€ Generate distractors"):
|
| 144 |
# Insert an HTML info icon with a tooltip at the top of the tab content.
|
| 145 |
gr.HTML(
|
|
|
|
| 184 |
diagnoser_button.click(
|
| 185 |
fn=run_diagnoser,
|
| 186 |
inputs=[diagnoser_input, model_choice, exercise_format, sampling_count],
|
| 187 |
+
outputs=[
|
| 188 |
+
diagnoser_response_1,
|
| 189 |
+
diagnoser_response_2,
|
| 190 |
+
diagnoser_response_3,
|
| 191 |
+
diagnoser_response_4,
|
| 192 |
+
diagnoser_response_5
|
| 193 |
+
]
|
| 194 |
)
|
| 195 |
+
|
| 196 |
distractors_button.click(
|
| 197 |
fn=run_distractors,
|
| 198 |
inputs=[distractors_input, model_choice, exercise_format, sampling_count],
|