ml-visoft commited on
Commit
b7aeae6
1 Parent(s): 1a80017

Touchups and size limiting

Browse files
Files changed (1) hide show
  1. main.py +20 -15
main.py CHANGED
@@ -27,7 +27,10 @@ OAUTH_CLIENT_SECRET = os.environ.get('OAUTH_CLIENT_SECRET')
27
  OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL", "https://huggingface.co")
28
  SPACE_HOST = os.environ.get('SPACE_HOST')
29
  HF_DATASET_AUTH_TOKEN = os.environ.get('HF_DATASET_AUTH_TOKEN', "(none)")
30
- DEFAULT_ANONYMOUS_USER_LEVEL = os.environ.get('DEFAULT_ANONYMOUS_USER_LEVEL', 0)
 
 
 
31
 
32
  LOCAL_STORAGE_PATH = ""
33
 
@@ -332,6 +335,9 @@ def post(session, qe_id:int, freeform_feedback:str):
332
  event_params={"question_evaluation_id":qe_id})
333
  )
334
 
 
 
 
335
  answer_eval_js = json.loads(qe_obj.answer_eval_text)
336
  answer_eval_js[0]["explanation"] = freeform_feedback
337
  qe_obj.submitted = True
@@ -551,7 +557,7 @@ def tl_html_results_and_feedback_area(session, show_submit_form=True):
551
 
552
 
553
  def tl_html_render_inputbox(session, target_html_id, region_html_id):
554
- txtarea = Textarea(id="ccodetoeval", name="ccodetoeval", placeholder="Enter a piece of C code", rows=3)
555
  form = Form(Group(txtarea, Button("Evaluate")),
556
  hx_post="/submit_to_eval",
557
  hx_swap="outerHTML",
@@ -567,26 +573,26 @@ def tl_html_render_inputbox(session, target_html_id, region_html_id):
567
 
568
  @rt("/submit_to_eval", methods="post")
569
  def post(session, ccodetoeval:str):
570
- # print(session)
571
  ulevel = get_user_level(session)
572
  if ulevel < 1:
573
  return P("Unauthorized. Log in to submit code to review.", style="background-color: #fff0f0;")
574
  if 'session_id' not in session:
575
  return P("submit_to_eval. Bad call. No session ID")
576
  session_id = session["session_id"]
577
- session_obj = Session_State_cls(
578
- session_id=session_id,
579
- state=EVAL_STATE_QUERY,
580
- submitted_date=datetime.isoformat(datetime.utcnow()),
581
- )
582
  save_to_storage(
583
  storage.NavigationEvent(event_type="/submit_to_eval", event_session_id=session_id, event_params={"ccodetoeval":ccodetoeval})
584
  )
 
 
 
 
 
 
585
 
586
- # we insert and we get the new primary key
587
- session_obj = session_state_table.insert(session_obj)
588
- # will be executed in another thread with magic @threaded
589
- call_gpt_and_store_result(session_obj.id, ccodetoeval)
590
  return tl_html_results_and_feedback_area(session), render_clear_area(session_id, HTML_CLEAR_FORM)
591
 
592
 
@@ -870,7 +876,8 @@ def get(session):
870
  auth_area,
871
  H1("Evaluate your C code!"),
872
  P("Enter your code in the textbox below and wait for answers."),
873
- P("!! The data will be saved and maybe made public !!"),
 
874
  ]
875
 
876
  input_area = tl_html_render_inputbox(session, target_html_id=HTML_RESULTS_AREA, region_html_id=HTML_SUBMIT_CODE_AREA)
@@ -880,6 +887,4 @@ def get(session):
880
  return title, Main( *preamble, input_area, results_feedback_area, clear_area)
881
 
882
 
883
-
884
-
885
  serve()
 
27
  OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL", "https://huggingface.co")
28
  SPACE_HOST = os.environ.get('SPACE_HOST')
29
  HF_DATASET_AUTH_TOKEN = os.environ.get('HF_DATASET_AUTH_TOKEN', "(none)")
30
+ try:
31
+ DEFAULT_ANONYMOUS_USER_LEVEL = int(os.environ.get('DEFAULT_ANONYMOUS_USER_LEVEL', 0))
32
+ except:
33
+ DEFAULT_ANONYMOUS_USER_LEVEL = 0
34
 
35
  LOCAL_STORAGE_PATH = ""
36
 
 
335
  event_params={"question_evaluation_id":qe_id})
336
  )
337
 
338
+ if len(freeform_feedback) > 10000:
339
+ freeform_feedback = freeform_feedback[:10000]
340
+
341
  answer_eval_js = json.loads(qe_obj.answer_eval_text)
342
  answer_eval_js[0]["explanation"] = freeform_feedback
343
  qe_obj.submitted = True
 
557
 
558
 
559
  def tl_html_render_inputbox(session, target_html_id, region_html_id):
560
+ txtarea = Textarea(id="ccodetoeval", name="ccodetoeval", placeholder="Paste a piece of C code here.", rows=3)
561
  form = Form(Group(txtarea, Button("Evaluate")),
562
  hx_post="/submit_to_eval",
563
  hx_swap="outerHTML",
 
573
 
574
  @rt("/submit_to_eval", methods="post")
575
  def post(session, ccodetoeval:str):
 
576
  ulevel = get_user_level(session)
577
  if ulevel < 1:
578
  return P("Unauthorized. Log in to submit code to review.", style="background-color: #fff0f0;")
579
  if 'session_id' not in session:
580
  return P("submit_to_eval. Bad call. No session ID")
581
  session_id = session["session_id"]
 
 
 
 
 
582
  save_to_storage(
583
  storage.NavigationEvent(event_type="/submit_to_eval", event_session_id=session_id, event_params={"ccodetoeval":ccodetoeval})
584
  )
585
+ if len(ccodetoeval) > 100 and len(ccodetoeval) < 40000:
586
+ session_obj = Session_State_cls(
587
+ session_id=session_id,
588
+ state=EVAL_STATE_QUERY,
589
+ submitted_date=datetime.isoformat(datetime.utcnow()),
590
+ )
591
 
592
+ # we insert and we get the new primary key
593
+ session_obj = session_state_table.insert(session_obj)
594
+ # will be executed in another thread with magic @threaded
595
+ call_gpt_and_store_result(session_obj.id, ccodetoeval)
596
  return tl_html_results_and_feedback_area(session), render_clear_area(session_id, HTML_CLEAR_FORM)
597
 
598
 
 
876
  auth_area,
877
  H1("Evaluate your C code!"),
878
  P("Enter your code in the textbox below and wait for answers."),
879
+ P("!! The data will be saved and maybe made public !!", style="background-color: #f0fff0;"),
880
+ P("Hint: Don't evaluate more than ~ 1000 LoC."),
881
  ]
882
 
883
  input_area = tl_html_render_inputbox(session, target_html_id=HTML_RESULTS_AREA, region_html_id=HTML_SUBMIT_CODE_AREA)
 
887
  return title, Main( *preamble, input_area, results_feedback_area, clear_area)
888
 
889
 
 
 
890
  serve()