Spaces:
Running
on
Zero
Running
on
Zero
Martín Santillán Cooper
commited on
Commit
•
e453066
1
Parent(s):
d57c940
result: change html to textbox
Browse files- app.py +8 -14
- styles.css +0 -4
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'], 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 |
-
|
37 |
}
|
38 |
|
39 |
def change_button_color(event: gr.EventData):
|
@@ -49,9 +49,9 @@ def on_submit(criteria, context, user_message, assistant_message, state):
|
|
49 |
}, state['selected_sub_catalog'])
|
50 |
logger.debug(f"Starting evaluation for subcatelog {state['selected_sub_catalog']} and criteria name {state['selected_criteria_name']}")
|
51 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
52 |
-
|
53 |
-
html_str = f"<p>{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} <strong>{result_label}</strong></p>"
|
54 |
-
|
55 |
return gr.update(value=html_str)
|
56 |
|
57 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
@@ -148,9 +148,7 @@ with gr.Blocks(
|
|
148 |
|
149 |
submit_button = gr.Button("Evaluate", variant='primary',icon=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'send-white.png'), elem_classes='submit-button')
|
150 |
|
151 |
-
|
152 |
-
evaluation_results_label = gr.HTML("<span>Results</span>", elem_classes='result-title', visible=False)
|
153 |
-
result_text = gr.HTML(elem_classes=['result-text', 'input-box', 'read-only', 'block'], visible=False, value='')
|
154 |
|
155 |
with Modal(visible=False, elem_classes='modal') as modal:
|
156 |
prompt = gr.Markdown('')
|
@@ -162,12 +160,8 @@ with gr.Blocks(
|
|
162 |
).then(lambda: gr.update(visible=True), None, modal)
|
163 |
|
164 |
submit_button \
|
165 |
-
.click(
|
166 |
-
|
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],
|
@@ -177,7 +171,7 @@ with gr.Blocks(
|
|
177 |
|
178 |
for button in [t for sub_catalog_name, sub_catalog_buttons in catalog_buttons.items() for t in sub_catalog_buttons.values()]:
|
179 |
button.click(update_selected_test_case, inputs=[button, state], outputs=[state])\
|
180 |
-
.then(on_test_case_click, inputs=state, outputs={test_case_name, criteria, context, user_message, assistant_message,
|
181 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
182 |
|
183 |
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_text: gr.update(visible=False, value='')
|
37 |
}
|
38 |
|
39 |
def change_button_color(event: gr.EventData):
|
|
|
49 |
}, state['selected_sub_catalog'])
|
50 |
logger.debug(f"Starting evaluation for subcatelog {state['selected_sub_catalog']} and criteria name {state['selected_criteria_name']}")
|
51 |
result_label = generate_text(prompt)['assessment'] # Yes or No
|
52 |
+
|
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"{get_result_description(state['selected_sub_catalog'], state['selected_criteria_name'])} {result_label}"
|
55 |
return gr.update(value=html_str)
|
56 |
|
57 |
def on_show_prompt_click(criteria, context, user_message, assistant_message, state):
|
|
|
148 |
|
149 |
submit_button = gr.Button("Evaluate", variant='primary',icon=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'send-white.png'), elem_classes='submit-button')
|
150 |
|
151 |
+
result_text = gr.Textbox(label='Result', elem_classes=['result-text', 'read-only', 'input-box'], visible=False, value='')
|
|
|
|
|
152 |
|
153 |
with Modal(visible=False, elem_classes='modal') as modal:
|
154 |
prompt = gr.Markdown('')
|
|
|
160 |
).then(lambda: gr.update(visible=True), None, modal)
|
161 |
|
162 |
submit_button \
|
163 |
+
.click(lambda: gr.update(visible=True, value=''), None, result_text) \
|
164 |
+
.then(
|
|
|
|
|
|
|
|
|
165 |
on_submit,
|
166 |
inputs=[criteria, context, user_message, assistant_message, state],
|
167 |
outputs=[result_text],
|
|
|
171 |
|
172 |
for button in [t for sub_catalog_name, sub_catalog_buttons in catalog_buttons.items() for t in sub_catalog_buttons.values()]:
|
173 |
button.click(update_selected_test_case, inputs=[button, state], outputs=[state])\
|
174 |
+
.then(on_test_case_click, inputs=state, outputs={test_case_name, criteria, context, user_message, assistant_message, result_text}) \
|
175 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
176 |
|
177 |
demo.launch(server_name='0.0.0.0')
|
styles.css
CHANGED
@@ -81,10 +81,6 @@
|
|
81 |
/* background-color: var(--background-fill-secondary); */
|
82 |
}
|
83 |
|
84 |
-
.result-text {
|
85 |
-
background-color: var(--block-background-fill);
|
86 |
-
}
|
87 |
-
|
88 |
.result-text p {
|
89 |
box-shadow: none;
|
90 |
}
|
|
|
81 |
/* background-color: var(--background-fill-secondary); */
|
82 |
}
|
83 |
|
|
|
|
|
|
|
|
|
84 |
.result-text p {
|
85 |
box-shadow: none;
|
86 |
}
|