Spaces:
Running
on
Zero
Running
on
Zero
Martín Santillán Cooper
commited on
Commit
•
0b32e5e
1
Parent(s):
3ae940c
improve progress flickering
Browse files- app.py +8 -8
- styles.css +4 -0
app.py
CHANGED
@@ -33,9 +33,7 @@ def on_test_case_click(state: gr.State):
|
|
33 |
context: gr.update(value=selected_test_case['context'], visible=True) if selected_test_case['context'] is not None else gr.update(visible=False, value=''),
|
34 |
user_message: gr.update(value=selected_test_case['user_message'], interactive=True, elem_classes=['input-box']) if selected_sub_catalog != 'harmful_content_in_assistant_response' else gr.update(value=selected_test_case['user_message'], interactive=False, elem_classes=['read-only', 'input-box']),
|
35 |
assistant_message: gr.update(value=selected_test_case['assistant_message'], visible=True) if selected_test_case['assistant_message'] is not None else gr.update(visible=False, value=''),
|
36 |
-
result_text: gr.update(value='', visible=False),
|
37 |
result_container: gr.update(visible=False),
|
38 |
-
evaluation_results_label: gr.update(visible=False)
|
39 |
}
|
40 |
|
41 |
def change_button_color(event: gr.EventData):
|
@@ -54,7 +52,7 @@ def on_submit(criteria, context, user_message, assistant_message, state):
|
|
54 |
# result_str = f"Is the {evaluated_component} message harmful based on the risk definition: {result_label}"
|
55 |
html_str = f"<p>{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} <strong>{result_label}</strong></p>"
|
56 |
# html_str = f"Is the {evaluated_component} {evaluated_component_adjective}: {result_label}"
|
57 |
-
return
|
58 |
|
59 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
60 |
prompt = get_prompt_from_test_case({
|
@@ -138,7 +136,7 @@ with gr.Blocks(
|
|
138 |
accordions.append(accordion)
|
139 |
|
140 |
with gr.Column(visible=True, scale=1) as test_case_content:
|
141 |
-
with gr.Row():
|
142 |
test_case_name = gr.HTML(f'<h2>{to_title_case(starting_test_case["name"])}</h2>', elem_classes='subtitle')
|
143 |
show_propt_button = gr.Button('Show prompt', size='sm', scale=0, min_width=110)
|
144 |
|
@@ -165,18 +163,20 @@ with gr.Blocks(
|
|
165 |
|
166 |
submit_button \
|
167 |
.click(
|
168 |
-
lambda: [gr.update(visible=True), gr.update(visible=
|
169 |
inputs=None,
|
170 |
-
outputs=[result_container, evaluation_results_label, result_text]
|
|
|
171 |
).then(
|
172 |
on_submit,
|
173 |
inputs=[criteria, context, user_message, assistant_message, state],
|
174 |
-
outputs=[result_text
|
175 |
)
|
|
|
176 |
|
177 |
for button in [t for sub_catalog_name, sub_catalog_buttons in catalog_buttons.items() for t in sub_catalog_buttons.values()]:
|
178 |
button.click(update_selected_test_case, inputs=[button, state], outputs=[state])\
|
179 |
-
.then(on_test_case_click, inputs=state, outputs={test_case_name, criteria, context, user_message, assistant_message,
|
180 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
181 |
|
182 |
demo.launch(server_name='0.0.0.0')
|
|
|
33 |
context: gr.update(value=selected_test_case['context'], visible=True) if selected_test_case['context'] is not None else gr.update(visible=False, value=''),
|
34 |
user_message: gr.update(value=selected_test_case['user_message'], interactive=True, elem_classes=['input-box']) if selected_sub_catalog != 'harmful_content_in_assistant_response' else gr.update(value=selected_test_case['user_message'], interactive=False, elem_classes=['read-only', 'input-box']),
|
35 |
assistant_message: gr.update(value=selected_test_case['assistant_message'], visible=True) if selected_test_case['assistant_message'] is not None else gr.update(visible=False, value=''),
|
|
|
36 |
result_container: gr.update(visible=False),
|
|
|
37 |
}
|
38 |
|
39 |
def change_button_color(event: gr.EventData):
|
|
|
52 |
# result_str = f"Is the {evaluated_component} message harmful based on the risk definition: {result_label}"
|
53 |
html_str = f"<p>{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} <strong>{result_label}</strong></p>"
|
54 |
# html_str = f"Is the {evaluated_component} {evaluated_component_adjective}: {result_label}"
|
55 |
+
return gr.update(value=html_str)
|
56 |
|
57 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
58 |
prompt = get_prompt_from_test_case({
|
|
|
136 |
accordions.append(accordion)
|
137 |
|
138 |
with gr.Column(visible=True, scale=1) as test_case_content:
|
139 |
+
with gr.Row(elem_classes='no-stretch'):
|
140 |
test_case_name = gr.HTML(f'<h2>{to_title_case(starting_test_case["name"])}</h2>', elem_classes='subtitle')
|
141 |
show_propt_button = gr.Button('Show prompt', size='sm', scale=0, min_width=110)
|
142 |
|
|
|
163 |
|
164 |
submit_button \
|
165 |
.click(
|
166 |
+
lambda: [gr.update(visible=True), gr.update(visible=True), gr.update(visible=True, value='')],
|
167 |
inputs=None,
|
168 |
+
outputs=[result_container, evaluation_results_label, result_text],
|
169 |
+
show_progress=False
|
170 |
).then(
|
171 |
on_submit,
|
172 |
inputs=[criteria, context, user_message, assistant_message, state],
|
173 |
+
outputs=[result_text]
|
174 |
)
|
175 |
+
|
176 |
|
177 |
for button in [t for sub_catalog_name, sub_catalog_buttons in catalog_buttons.items() for t in sub_catalog_buttons.values()]:
|
178 |
button.click(update_selected_test_case, inputs=[button, state], outputs=[state])\
|
179 |
+
.then(on_test_case_click, inputs=state, outputs={test_case_name, criteria, context, user_message, assistant_message, result_container}) \
|
180 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
181 |
|
182 |
demo.launch(server_name='0.0.0.0')
|
styles.css
CHANGED
@@ -129,4 +129,8 @@
|
|
129 |
|
130 |
.subtitle-harms {
|
131 |
padding-bottom: 8px;
|
|
|
|
|
|
|
|
|
132 |
}
|
|
|
129 |
|
130 |
.subtitle-harms {
|
131 |
padding-bottom: 8px;
|
132 |
+
}
|
133 |
+
|
134 |
+
.no-stretch {
|
135 |
+
align-items: flex-start;
|
136 |
}
|