ziyan14 commited on
Commit
c957ff0
·
verified ·
1 Parent(s): 07de234

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -266,6 +266,7 @@ def validate_and_evaluate(description: str, code: str):
266
  # ---------------------------------------------------------------------------
267
  # MODULE 1 — UI Module
268
  # ---------------------------------------------------------------------------
 
269
  CUSTOM_CSS = """
270
  @import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');
271
  *, *::before, *::after { box-sizing: border-box; }
@@ -449,6 +450,7 @@ INPUT_HINT_HTML = """
449
  </div>
450
  """
451
 
 
452
  def build_ui(evaluate_fn):
453
 
454
  def _split_metrics(metrics_str: str):
@@ -483,21 +485,37 @@ def build_ui(evaluate_fn):
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
 
@@ -506,14 +524,14 @@ def build_ui(evaluate_fn):
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,7 +544,8 @@ def build_ui(evaluate_fn):
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,4 +558,5 @@ def build_ui(evaluate_fn):
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)
 
 
266
  # ---------------------------------------------------------------------------
267
  # MODULE 1 — UI Module
268
  # ---------------------------------------------------------------------------
269
+
270
  CUSTOM_CSS = """
271
  @import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');
272
  *, *::before, *::after { box-sizing: border-box; }
 
450
  </div>
451
  """
452
 
453
+
454
  def build_ui(evaluate_fn):
455
 
456
  def _split_metrics(metrics_str: str):
 
485
  placeholder=(
486
  "Describe what the Python code is supposed to do…\n\n"
487
  "Example: Write a function that accepts a list of integers "
488
+ "and returns the sum of all even numbers. It should handle "
489
+ "empty lists by returning 0 and ignore non-integer values."
490
  ),
491
+ lines=10,
492
+ max_lines=20,
493
+ elem_id="desc-input",
494
  )
495
  code_input = gr.Textbox(
496
  label="Python Code",
497
+ placeholder=(
498
+ "# Paste your Python code here…\n\n"
499
+ "# Note: Ensure proper indentation for accurate evaluation.\n\n"
500
+ "def example(numbers):\n"
501
+ " total = 0\n"
502
+ " for item in numbers:\n"
503
+ " if item % 2 == 0:\n"
504
+ " total += item\n"
505
+ " return total\n"
506
+ ),
507
+ lines=10,
508
+ max_lines=30,
509
+ elem_id="code-input",
510
  )
511
 
512
  gr.HTML(INPUT_HINT_HTML)
513
 
514
  with gr.Row():
515
+ eval_btn = gr.Button("Evaluate", variant="primary",
516
+ elem_id="eval-btn", scale=0)
517
+ clear_btn = gr.Button("Clear", variant="secondary",
518
+ elem_id="clear-btn", scale=0)
519
 
520
  gr.HTML(RESULTS_HEADING_HTML)
521
 
 
524
  accuracy_out = gr.Textbox(label="Accuracy", interactive=False, elem_id="accuracy-out", scale=1)
525
  summary_out = gr.Textbox(label="Summary", interactive=False, elem_id="summary-out", scale=2, lines=3)
526
 
527
+ issues_out = gr.Textbox(label="Issues Detected", interactive=False, lines=5, elem_id="issues-out")
528
  error_out = gr.Textbox(label="Status / Errors", interactive=False, visible=True, elem_id="error-out")
529
 
530
  gr.HTML("""
531
  <div style="text-align:right;font-size:11px;color:#4A4E60;margin-top:8px;">
532
  Press <kbd style="background:#1E2028;border:1px solid #3A3E52;border-radius:4px;
533
  padding:2px 6px;font-family:'Space Mono',monospace;font-size:10px;color:#9DA0B0;">
534
+ Ctrl+Enter</kbd> inside any input to evaluate
535
  </div>
536
  """)
537
 
 
544
  return "", "", "", "", "", ""
545
 
546
  clear_btn.click(
547
+ fn=_clear,
548
+ inputs=[],
549
  outputs=[description_input, code_input,
550
  verdict_out, accuracy_out, summary_out, issues_out],
551
  )
 
558
  # ---------------------------------------------------------------------------
559
  if __name__ == "__main__":
560
  app = build_ui(validate_and_evaluate)
561
+ app.launch(server_name="0.0.0.0", server_port=7860, share=False,
562
+ show_error=True, css=CUSTOM_CSS)