ziyan14 commited on
Commit
218d561
·
verified ·
1 Parent(s): 750cd8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -84
app.py CHANGED
@@ -49,7 +49,6 @@ description and a Python code snippet, then produce a structured evaluation repo
49
  - Do NOT execute the code.
50
  - Base your evaluation solely on static code analysis and logical reasoning.
51
  - Keep feedback concise, clear, and actionable.
52
- - Pay close attention to operators (+, -, *, /) and ensure they match the description exactly.
53
  - Your response MUST follow the output format exactly.
54
  ### OUTPUT FORMAT
55
  Respond only with the following structure — no extra text before or after:
@@ -416,21 +415,11 @@ body, .gradio-container {
416
  padding: 16px !important; color: #C0C3D0 !important;
417
  cursor: default !important; min-height: 120px !important;
418
  }
419
- #error-out {
420
- width: 100% !important;
421
- }
422
  #error-out textarea {
423
- background: #1A0E0E !important;
424
- border: 1px solid #5a2020 !important;
425
- border-radius: 10px !important;
426
- font-family: 'DM Sans', sans-serif !important;
427
- font-size: 13.5px !important;
428
- padding: 14px 16px !important;
429
- color: #F0997B !important;
430
- cursor: default !important;
431
- min-height: 120px !important;
432
- width: 100% !important;
433
- box-sizing: border-box !important;
434
  }
435
  .divider { height: 1px; background: #2E3140; margin: 20px 0; }
436
  footer { display: none !important; }
@@ -460,7 +449,6 @@ INPUT_HINT_HTML = """
460
  </div>
461
  """
462
 
463
-
464
  def build_ui(evaluate_fn):
465
 
466
  def _split_metrics(metrics_str: str):
@@ -477,32 +465,13 @@ def build_ui(evaluate_fn):
477
  def _ui_evaluate(description: str, code: str):
478
  verdict, metrics, issues, error = evaluate_fn(description, code)
479
  accuracy, summary = _split_metrics(metrics)
480
-
481
- if error:
482
- # Top row stays visible but empty — keeps full width
483
- return (
484
- gr.update(value="", visible=True), # verdict
485
- gr.update(value="", visible=True), # accuracy
486
- gr.update(value="", visible=True), # summary
487
- gr.update(value="", visible=False), # issues — hidden
488
- gr.update(value=error, visible=True), # error — shown
489
- )
490
-
491
- # Success — show results, hide error
492
  if "PASS" in verdict.upper():
493
  verdict_display = "✅ PASS"
494
  elif "FAIL" in verdict.upper():
495
  verdict_display = "❌ FAIL"
496
  else:
497
  verdict_display = verdict or ""
498
-
499
- return (
500
- gr.update(value=verdict_display, visible=True), # verdict
501
- gr.update(value=accuracy, visible=True), # accuracy
502
- gr.update(value=summary, visible=True), # summary
503
- gr.update(value=issues, visible=True), # issues — shown
504
- gr.update(value="", visible=False), # error — hidden
505
- )
506
 
507
  with gr.Blocks(title="Python Code Evaluator") as demo:
508
 
@@ -514,69 +483,37 @@ def build_ui(evaluate_fn):
514
  placeholder=(
515
  "Describe what the Python code is supposed to do…\n\n"
516
  "Example: Write a function that accepts a list of integers "
517
- "and returns the sum of all even numbers. It should handle "
518
- "empty lists by returning 0 and ignore non-integer values."
519
  ),
520
- lines=10,
521
- max_lines=20,
522
- elem_id="desc-input",
523
  )
524
  code_input = gr.Textbox(
525
  label="Python Code",
526
- placeholder=(
527
- "# Paste your Python code here…\n\n"
528
- "# Note: Ensure proper indentation for accurate evaluation.\n\n"
529
- "def example(numbers):\n"
530
- " total = 0\n"
531
- " for item in numbers:\n"
532
- " if item % 2 == 0:\n"
533
- " total += item\n"
534
- " return total\n"
535
- ),
536
- lines=10,
537
- max_lines=30,
538
- elem_id="code-input",
539
  )
540
 
541
  gr.HTML(INPUT_HINT_HTML)
542
 
543
  with gr.Row():
544
- eval_btn = gr.Button("Evaluate", variant="primary",
545
- elem_id="eval-btn", scale=0)
546
- clear_btn = gr.Button("Clear", variant="secondary",
547
- elem_id="clear-btn", scale=0)
548
 
549
  gr.HTML(RESULTS_HEADING_HTML)
550
 
551
- # Top row — always visible to preserve full width
552
  with gr.Row(equal_height=True):
553
- verdict_out = gr.Textbox(label="Verdict", interactive=False, elem_id="verdict-out", scale=1)
554
- accuracy_out = gr.Textbox(label="Accuracy", interactive=False, elem_id="accuracy-out", scale=1)
555
- summary_out = gr.Textbox(label="Summary", interactive=False, elem_id="summary-out", scale=2, lines=3)
556
-
557
- # Issues and error swap in the same spot
558
- issues_out = gr.Textbox(
559
- label="Issues Detected",
560
- interactive=False,
561
- lines=5,
562
- visible=True,
563
- elem_id="issues-out",
564
- )
565
 
566
- with gr.Row():
567
- error_out = gr.Textbox(
568
- label="Status / Errors",
569
- interactive=False,
570
- visible=False, # hidden by default
571
- elem_id="error-out",
572
- scale=1,
573
- )
574
 
575
  gr.HTML("""
576
  <div style="text-align:right;font-size:11px;color:#4A4E60;margin-top:8px;">
577
  Press <kbd style="background:#1E2028;border:1px solid #3A3E52;border-radius:4px;
578
  padding:2px 6px;font-family:'Space Mono',monospace;font-size:10px;color:#9DA0B0;">
579
- Ctrl+Enter</kbd> inside any input to evaluate
580
  </div>
581
  """)
582
 
@@ -589,8 +526,7 @@ def build_ui(evaluate_fn):
589
  return "", "", "", "", "", ""
590
 
591
  clear_btn.click(
592
- fn=_clear,
593
- inputs=[],
594
  outputs=[description_input, code_input,
595
  verdict_out, accuracy_out, summary_out, issues_out],
596
  )
@@ -603,5 +539,4 @@ def build_ui(evaluate_fn):
603
  # ---------------------------------------------------------------------------
604
  if __name__ == "__main__":
605
  app = build_ui(validate_and_evaluate)
606
- app.launch(server_name="0.0.0.0", server_port=7860, share=False,
607
- show_error=True, css=CUSTOM_CSS)
 
49
  - Do NOT execute the code.
50
  - Base your evaluation solely on static code analysis and logical reasoning.
51
  - Keep feedback concise, clear, and actionable.
 
52
  - Your response MUST follow the output format exactly.
53
  ### OUTPUT FORMAT
54
  Respond only with the following structure — no extra text before or after:
 
415
  padding: 16px !important; color: #C0C3D0 !important;
416
  cursor: default !important; min-height: 120px !important;
417
  }
 
 
 
418
  #error-out textarea {
419
+ background: #1A0E0E !important; border: 1px solid #5a2020 !important;
420
+ border-radius: 10px !important; font-family: 'DM Sans', sans-serif !important;
421
+ font-size: 13.5px !important; padding: 14px 16px !important;
422
+ color: #F0997B !important; cursor: default !important;
 
 
 
 
 
 
 
423
  }
424
  .divider { height: 1px; background: #2E3140; margin: 20px 0; }
425
  footer { display: none !important; }
 
449
  </div>
450
  """
451
 
 
452
  def build_ui(evaluate_fn):
453
 
454
  def _split_metrics(metrics_str: str):
 
465
  def _ui_evaluate(description: str, code: str):
466
  verdict, metrics, issues, error = evaluate_fn(description, code)
467
  accuracy, summary = _split_metrics(metrics)
 
 
 
 
 
 
 
 
 
 
 
 
468
  if "PASS" in verdict.upper():
469
  verdict_display = "✅ PASS"
470
  elif "FAIL" in verdict.upper():
471
  verdict_display = "❌ FAIL"
472
  else:
473
  verdict_display = verdict or ""
474
+ return verdict_display, accuracy, summary, issues, error
 
 
 
 
 
 
 
475
 
476
  with gr.Blocks(title="Python Code Evaluator") as demo:
477
 
 
483
  placeholder=(
484
  "Describe what the Python code is supposed to do…\n\n"
485
  "Example: Write a function that accepts a list of integers "
486
+ "and returns the sum of all even numbers."
 
487
  ),
488
+ lines=10, max_lines=20, elem_id="desc-input",
 
 
489
  )
490
  code_input = gr.Textbox(
491
  label="Python Code",
492
+ placeholder="# Paste your Python code here…\n\ndef example(data):\n pass\n",
493
+ lines=10, max_lines=30, elem_id="code-input",
 
 
 
 
 
 
 
 
 
 
 
494
  )
495
 
496
  gr.HTML(INPUT_HINT_HTML)
497
 
498
  with gr.Row():
499
+ eval_btn = gr.Button("Evaluate", variant="primary", elem_id="eval-btn", scale=0)
500
+ clear_btn = gr.Button("Clear", variant="secondary", elem_id="clear-btn", scale=0)
 
 
501
 
502
  gr.HTML(RESULTS_HEADING_HTML)
503
 
 
504
  with gr.Row(equal_height=True):
505
+ verdict_out = gr.Textbox(label="Verdict", interactive=False, elem_id="verdict-out", scale=1)
506
+ accuracy_out = gr.Textbox(label="Accuracy", interactive=False, elem_id="accuracy-out", scale=1)
507
+ summary_out = gr.Textbox(label="Summary", interactive=False, elem_id="summary-out", scale=2, lines=3)
 
 
 
 
 
 
 
 
 
508
 
509
+ issues_out = gr.Textbox(label="Issues Detected", interactive=False, lines=5, elem_id="issues-out")
510
+ error_out = gr.Textbox(label="Status / Errors", interactive=False, visible=True, elem_id="error-out")
 
 
 
 
 
 
511
 
512
  gr.HTML("""
513
  <div style="text-align:right;font-size:11px;color:#4A4E60;margin-top:8px;">
514
  Press <kbd style="background:#1E2028;border:1px solid #3A3E52;border-radius:4px;
515
  padding:2px 6px;font-family:'Space Mono',monospace;font-size:10px;color:#9DA0B0;">
516
+ Ctrl+Enter</kbd> to evaluate
517
  </div>
518
  """)
519
 
 
526
  return "", "", "", "", "", ""
527
 
528
  clear_btn.click(
529
+ fn=_clear, inputs=[],
 
530
  outputs=[description_input, code_input,
531
  verdict_out, accuracy_out, summary_out, issues_out],
532
  )
 
539
  # ---------------------------------------------------------------------------
540
  if __name__ == "__main__":
541
  app = build_ui(validate_and_evaluate)
542
+ app.launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True, css=CUSTOM_CSS)