Spaces:
Running
on
Zero
Running
on
Zero
Martín Santillán Cooper
commited on
Commit
•
530c8fb
1
Parent(s):
cab16f9
Design improvements
Browse files
app.py
CHANGED
@@ -33,7 +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'], elem_classes=[], interactive=True),# if selected_sub_catalog != 'harmful_content_in_assistant_message' else gr.update(value=selected_test_case['user_message'], interactive=False, elem_classes=['read-only']),
|
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=''),
|
37 |
}
|
38 |
|
39 |
def change_button_color(event: gr.EventData):
|
@@ -51,7 +51,7 @@ def on_submit(criteria, context, user_message, assistant_message, state):
|
|
51 |
evaluated_component_adjective = get_evaluated_component_adjective(state['selected_sub_catalog'], state['selected_criteria_name'])
|
52 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
53 |
result_str = f"Is the {evaluated_component} message harmful based on the risk definition: {result_label}"
|
54 |
-
return result_str
|
55 |
|
56 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
57 |
prompt = get_prompt_from_test_case({
|
@@ -100,7 +100,9 @@ with gr.Blocks(
|
|
100 |
accordions.append(accordion)
|
101 |
|
102 |
with gr.Column(visible=True) as test_case_content:
|
103 |
-
|
|
|
|
|
104 |
|
105 |
gr.HTML("Evaluation Criteria", elem_classes='subtitle')
|
106 |
criteria = gr.Textbox(label="Definition", lines=3, interactive=False, value=starting_test_case['criteria'], elem_classes=['read-only'])
|
@@ -111,12 +113,10 @@ with gr.Blocks(
|
|
111 |
assistant_message = gr.Textbox(label="Assistant Message", lines=3, interactive=True, visible=False, value=starting_test_case['assistant_message'])
|
112 |
|
113 |
submit_button = gr.Button("Evaluate", variant='primary')
|
114 |
-
gr.HTML("Evaluation results", elem_classes='subtitle')
|
115 |
-
|
116 |
-
result_text = gr.Textbox(label="Result", interactive=False, elem_classes=['read-only', "result-text"], max_lines=1)
|
117 |
-
|
118 |
-
show_propt_button = gr.Button('Show prompt', size='sm', scale=0)
|
119 |
|
|
|
|
|
|
|
120 |
with Modal(visible=False) as modal:
|
121 |
prompt = gr.Markdown("Hello world!")
|
122 |
|
@@ -126,7 +126,7 @@ with gr.Blocks(
|
|
126 |
outputs=prompt
|
127 |
).then(lambda: gr.update(visible=True), None, modal)
|
128 |
|
129 |
-
submit_button.click(
|
130 |
on_submit,
|
131 |
inputs=[criteria, context, user_message, assistant_message, state],
|
132 |
outputs=[result_text])
|
|
|
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'], elem_classes=[], interactive=True),# if selected_sub_catalog != 'harmful_content_in_assistant_message' else gr.update(value=selected_test_case['user_message'], interactive=False, elem_classes=['read-only']),
|
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 |
}
|
38 |
|
39 |
def change_button_color(event: gr.EventData):
|
|
|
51 |
evaluated_component_adjective = get_evaluated_component_adjective(state['selected_sub_catalog'], state['selected_criteria_name'])
|
52 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
53 |
result_str = f"Is the {evaluated_component} message harmful based on the risk definition: {result_label}"
|
54 |
+
return gr.update(value=result_str)
|
55 |
|
56 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
57 |
prompt = get_prompt_from_test_case({
|
|
|
100 |
accordions.append(accordion)
|
101 |
|
102 |
with gr.Column(visible=True) as test_case_content:
|
103 |
+
with gr.Row():
|
104 |
+
test_case_name = gr.HTML(f'<h2>{to_title_case(starting_test_case["name"])}</h2>')
|
105 |
+
show_propt_button = gr.Button('Show prompt', size='sm', scale=0, min_width=110)
|
106 |
|
107 |
gr.HTML("Evaluation Criteria", elem_classes='subtitle')
|
108 |
criteria = gr.Textbox(label="Definition", lines=3, interactive=False, value=starting_test_case['criteria'], elem_classes=['read-only'])
|
|
|
113 |
assistant_message = gr.Textbox(label="Assistant Message", lines=3, interactive=True, visible=False, value=starting_test_case['assistant_message'])
|
114 |
|
115 |
submit_button = gr.Button("Evaluate", variant='primary')
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
evaluation_results_label = gr.HTML("Evaluation results", elem_classes='subtitle', visible=False)
|
118 |
+
result_text = gr.Textbox(label="Result", interactive=False, elem_classes=['read-only', "result-text"], max_lines=1, visible=False)
|
119 |
+
|
120 |
with Modal(visible=False) as modal:
|
121 |
prompt = gr.Markdown("Hello world!")
|
122 |
|
|
|
126 |
outputs=prompt
|
127 |
).then(lambda: gr.update(visible=True), None, modal)
|
128 |
|
129 |
+
submit_button.click(lambda: gr.update(visible=True), inputs=None, outputs=result_text).then(
|
130 |
on_submit,
|
131 |
inputs=[criteria, context, user_message, assistant_message, state],
|
132 |
outputs=[result_text])
|