Spaces:
Sleeping
Sleeping
Styling
Browse files
main.py
CHANGED
@@ -141,6 +141,7 @@ else:
|
|
141 |
|
142 |
hdrs = (
|
143 |
HighlightJS(langs=['python', 'c', 'c++']),
|
|
|
144 |
# Meta(name="htmx-config", content='{"defaultSwapStyle":"outerHTML"}')
|
145 |
)
|
146 |
|
@@ -232,11 +233,12 @@ def html_create_feedback_updown_button(qe_id, ans_id, selected=0, disabled=False
|
|
232 |
hx_swap="outerHTML", style=f"background-color:{up_col}")
|
233 |
down = Button("👎", hx_get=f"{toggle_url}/-1", disabled=disabled, target_id=html_target_id,
|
234 |
hx_swap="outerHTML", style=f"background-color:{down_col}")
|
235 |
-
button_row = Div(up, down, id=html_target_id
|
|
|
236 |
return button_row
|
237 |
|
238 |
|
239 |
-
def
|
240 |
"""
|
241 |
Will plot the + / - buttons for feedback.
|
242 |
|
@@ -248,7 +250,9 @@ def html_augment_evaluation_text_with_feedback(eval_html, qe_obj, ans_id):
|
|
248 |
answer_eval_js = json.loads(qe_obj.answer_eval_text)
|
249 |
buttons = html_create_feedback_updown_button(qe_obj.id, ans_id, answer_eval_js[ans_id]["EVAL"],
|
250 |
disabled=(qe_obj.submitted == 1))
|
251 |
-
final_div = Div(eval_html, buttons,
|
|
|
|
|
252 |
return final_div
|
253 |
|
254 |
|
@@ -355,13 +359,16 @@ def html_format_code_review_form(qe_obj):
|
|
355 |
list_of_citerias = []
|
356 |
for caug_code, caug_txt in eval_code.CODE_AUGMENTATIONS:
|
357 |
crit_tag = [H3(caug_code), P(caug_txt)]
|
358 |
-
list_of_citerias.extend(crit_tag)
|
359 |
# yeah, I know . . .
|
|
|
360 |
for k, eval_line in enumerate(enhanced_answer):
|
361 |
if caug_code == eval_line["criteria"]:
|
362 |
-
eval_txt = P(eval_line["explanation"])
|
363 |
-
eval_txt_fb =
|
364 |
-
|
|
|
|
|
365 |
textual_feedback = html_get_textual_feedback_form(qe_obj)
|
366 |
return html_render_code_output(c_code), *list_of_citerias, textual_feedback
|
367 |
|
@@ -429,7 +436,7 @@ def html_render_code_output(code):
|
|
429 |
return txtarea
|
430 |
|
431 |
|
432 |
-
def html_render_answer_from_db(session_id):
|
433 |
eval_request_status, state_obj = get_latest_eval_request_status(session_id)
|
434 |
# state_rows = session_state_table(limit=1, where=f"session_id == '{session_id}'", order_by="id DESC")
|
435 |
# print(eval_request_status, state_obj)
|
@@ -442,7 +449,8 @@ def html_render_answer_from_db(session_id):
|
|
442 |
return (None,)
|
443 |
qe_obj = qe_obj_lst[0]
|
444 |
return (html_format_code_review_form(qe_obj),
|
445 |
-
html_render_inputbox(target_html_id=HTML_RESULTS_AREA,
|
|
|
446 |
if eval_request_status == EVAL_STATE_TIMEDOUT:
|
447 |
return html_eval_request_timed_out(),
|
448 |
if eval_request_status == EVAL_STATE_QUERY:
|
@@ -510,14 +518,14 @@ def call_gpt_and_store_result(session_obj_id, code_to_check):
|
|
510 |
traceback.print_exc()
|
511 |
|
512 |
|
513 |
-
def tl_html_results_and_feedback_area(session_id):
|
514 |
"""
|
515 |
Top level component that will render the code evaluation overlapped with feedback submission form.
|
516 |
|
517 |
:param session_id:
|
518 |
:return:
|
519 |
"""
|
520 |
-
results_feedback_area = html_render_answer_from_db(session_id)
|
521 |
return Div(*results_feedback_area, id=HTML_RESULTS_AREA)
|
522 |
|
523 |
|
@@ -570,7 +578,7 @@ def html_render_login_to_get_access_part(session):
|
|
570 |
:return:
|
571 |
"""
|
572 |
content = []
|
573 |
-
content.append(
|
574 |
content.append(P("We will record your name, hugginface name, hf profile page, email address. "
|
575 |
"We will try HARD not to make them public but . . ."))
|
576 |
content.append(P("Your feedback will be made public but in an anonymized form."))
|
@@ -621,7 +629,7 @@ function checkPopupClosed() {
|
|
621 |
href=redirect_link, onclick="return openPopup(this.href); return false;")
|
622 |
content.append(login_button)
|
623 |
content.append(P(" "))
|
624 |
-
div = Div(*content, id=HTML_USER_DATA)
|
625 |
return div
|
626 |
|
627 |
def html_render_welcome_user(user_info):
|
@@ -636,7 +644,7 @@ def html_render_welcome_user(user_info):
|
|
636 |
# content.append(Img(src=OPENID_PROVIDER_URL + user_info["picture"], alt="Picture"))
|
637 |
content.append(P("Your feedback will be made public but in an anonymized form."))
|
638 |
content.append(P(A("Logout", href=f"/logout")))
|
639 |
-
div = Div(*content, id=HTML_USER_DATA)
|
640 |
return div
|
641 |
|
642 |
|
@@ -777,10 +785,10 @@ def get(session):
|
|
777 |
]
|
778 |
|
779 |
input_area = html_render_inputbox(target_html_id=HTML_RESULTS_AREA, region_html_id=HTML_SUBMIT_CODE_AREA)
|
780 |
-
results_feedback_area = tl_html_results_and_feedback_area(session_id)
|
781 |
clear_area = render_clear_area(session_id, HTML_CLEAR_FORM)
|
782 |
# print(session)
|
783 |
-
return title, Main(*preamble, input_area, results_feedback_area, clear_area)
|
784 |
|
785 |
|
786 |
@rt("/submit_to_eval", methods="post")
|
|
|
141 |
|
142 |
hdrs = (
|
143 |
HighlightJS(langs=['python', 'c', 'c++']),
|
144 |
+
Link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css", type="text/css"),
|
145 |
# Meta(name="htmx-config", content='{"defaultSwapStyle":"outerHTML"}')
|
146 |
)
|
147 |
|
|
|
233 |
hx_swap="outerHTML", style=f"background-color:{up_col}")
|
234 |
down = Button("👎", hx_get=f"{toggle_url}/-1", disabled=disabled, target_id=html_target_id,
|
235 |
hx_swap="outerHTML", style=f"background-color:{down_col}")
|
236 |
+
button_row = Div(up, down, id=html_target_id, _class="box col-xs-1",
|
237 |
+
style=f"flex: 0 0 auto; display: flex; gap: 5px; margin-right: 10px;")
|
238 |
return button_row
|
239 |
|
240 |
|
241 |
+
def html_augment_signle_evaluation_text_with_feedback(eval_html, qe_obj, ans_id):
|
242 |
"""
|
243 |
Will plot the + / - buttons for feedback.
|
244 |
|
|
|
250 |
answer_eval_js = json.loads(qe_obj.answer_eval_text)
|
251 |
buttons = html_create_feedback_updown_button(qe_obj.id, ans_id, answer_eval_js[ans_id]["EVAL"],
|
252 |
disabled=(qe_obj.submitted == 1))
|
253 |
+
final_div = Div(eval_html, buttons,
|
254 |
+
style=" background-color: #f0f0f0; display: flex; "
|
255 |
+
"width: 98%; margin: 16px; padding: 3px; align-items: center;", cls="row")
|
256 |
return final_div
|
257 |
|
258 |
|
|
|
359 |
list_of_citerias = []
|
360 |
for caug_code, caug_txt in eval_code.CODE_AUGMENTATIONS:
|
361 |
crit_tag = [H3(caug_code), P(caug_txt)]
|
362 |
+
# list_of_citerias.extend(crit_tag)
|
363 |
# yeah, I know . . .
|
364 |
+
eval_txt_fb_list = []
|
365 |
for k, eval_line in enumerate(enhanced_answer):
|
366 |
if caug_code == eval_line["criteria"]:
|
367 |
+
eval_txt = Div(P(eval_line["explanation"]), style="flex: 1; margin-right: 10px;", cls="box col-xs-11")
|
368 |
+
eval_txt_fb = html_augment_signle_evaluation_text_with_feedback(eval_txt, qe_obj, k)
|
369 |
+
eval_txt_fb_list.append(eval_txt_fb)
|
370 |
+
criteria_div = Div(*crit_tag, *eval_txt_fb_list, style="border: 1px solid black; margin: 10px; padding: 10px")
|
371 |
+
list_of_citerias.append(criteria_div)
|
372 |
textual_feedback = html_get_textual_feedback_form(qe_obj)
|
373 |
return html_render_code_output(c_code), *list_of_citerias, textual_feedback
|
374 |
|
|
|
436 |
return txtarea
|
437 |
|
438 |
|
439 |
+
def html_render_answer_from_db(session_id, show_submit_form=True):
|
440 |
eval_request_status, state_obj = get_latest_eval_request_status(session_id)
|
441 |
# state_rows = session_state_table(limit=1, where=f"session_id == '{session_id}'", order_by="id DESC")
|
442 |
# print(eval_request_status, state_obj)
|
|
|
449 |
return (None,)
|
450 |
qe_obj = qe_obj_lst[0]
|
451 |
return (html_format_code_review_form(qe_obj),
|
452 |
+
html_render_inputbox(target_html_id=HTML_RESULTS_AREA,
|
453 |
+
region_html_id=HTML_SUBMIT_CODE_AREA) if show_submit_form else None)
|
454 |
if eval_request_status == EVAL_STATE_TIMEDOUT:
|
455 |
return html_eval_request_timed_out(),
|
456 |
if eval_request_status == EVAL_STATE_QUERY:
|
|
|
518 |
traceback.print_exc()
|
519 |
|
520 |
|
521 |
+
def tl_html_results_and_feedback_area(session_id, show_submit_form=True):
|
522 |
"""
|
523 |
Top level component that will render the code evaluation overlapped with feedback submission form.
|
524 |
|
525 |
:param session_id:
|
526 |
:return:
|
527 |
"""
|
528 |
+
results_feedback_area = html_render_answer_from_db(session_id, show_submit_form)
|
529 |
return Div(*results_feedback_area, id=HTML_RESULTS_AREA)
|
530 |
|
531 |
|
|
|
578 |
:return:
|
579 |
"""
|
580 |
content = []
|
581 |
+
content.append(H4("Log in to give feedback!"))
|
582 |
content.append(P("We will record your name, hugginface name, hf profile page, email address. "
|
583 |
"We will try HARD not to make them public but . . ."))
|
584 |
content.append(P("Your feedback will be made public but in an anonymized form."))
|
|
|
629 |
href=redirect_link, onclick="return openPopup(this.href); return false;")
|
630 |
content.append(login_button)
|
631 |
content.append(P(" "))
|
632 |
+
div = Div(*content, id=HTML_USER_DATA, style="background-color: #f0f0f0; padding: 10px;")
|
633 |
return div
|
634 |
|
635 |
def html_render_welcome_user(user_info):
|
|
|
644 |
# content.append(Img(src=OPENID_PROVIDER_URL + user_info["picture"], alt="Picture"))
|
645 |
content.append(P("Your feedback will be made public but in an anonymized form."))
|
646 |
content.append(P(A("Logout", href=f"/logout")))
|
647 |
+
div = Div(*content, id=HTML_USER_DATA, style="background-color: #f0f0f0; padding: 10px;")
|
648 |
return div
|
649 |
|
650 |
|
|
|
785 |
]
|
786 |
|
787 |
input_area = html_render_inputbox(target_html_id=HTML_RESULTS_AREA, region_html_id=HTML_SUBMIT_CODE_AREA)
|
788 |
+
results_feedback_area = tl_html_results_and_feedback_area(session_id, show_submit_form=False)
|
789 |
clear_area = render_clear_area(session_id, HTML_CLEAR_FORM)
|
790 |
# print(session)
|
791 |
+
return title, Main( *preamble, input_area, results_feedback_area, clear_area)
|
792 |
|
793 |
|
794 |
@rt("/submit_to_eval", methods="post")
|