czrrr commited on
Commit
a1ecd1b
·
verified ·
1 Parent(s): b09ef8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -5
app.py CHANGED
@@ -452,13 +452,22 @@ def run_current_evaluation_question(
452
 
453
  try:
454
  answer = BasicAgent()(question, task_id)
 
 
 
455
  updated = dict(answers or {})
456
  updated[str(task_id)] = answer
457
  dataframe = review_dataframe(questions, updated)
 
 
 
 
 
458
  return (
459
  answer,
460
  updated,
461
- "Questão executada e resposta salva. Revise o conteúdo antes de avançar.",
 
462
  progress_summary(questions, updated),
463
  readiness_summary(dataframe),
464
  dataframe,
@@ -475,6 +484,69 @@ def run_current_evaluation_question(
475
  )
476
 
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  def fetch_random_question():
479
  """Busca somente uma questão oficial aleatória, sem executar ou enviar."""
480
  try:
@@ -738,9 +810,13 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GAIA Agent Evaluation") as demo:
738
  evaluation_answers = gr.State({})
739
  current_task_id = gr.State("")
740
 
741
- load_questions_button = gr.Button(
742
- "Carregar as 20 questões", variant="secondary"
743
- )
 
 
 
 
744
  question_selector = gr.Dropdown(
745
  label="Escolha a questão",
746
  choices=[],
@@ -761,7 +837,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GAIA Agent Evaluation") as demo:
761
  )
762
  with gr.Row():
763
  run_current_button = gr.Button(
764
- "Executar somente esta questão", variant="primary"
765
  )
766
  save_answer_button = gr.Button("Salvar resposta revisada")
767
 
@@ -801,6 +877,17 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GAIA Agent Evaluation") as demo:
801
  results_table,
802
  ],
803
  )
 
 
 
 
 
 
 
 
 
 
 
804
  question_selector.change(
805
  fn=select_evaluation_question,
806
  inputs=[
 
452
 
453
  try:
454
  answer = BasicAgent()(question, task_id)
455
+ had_previous_answer = bool(
456
+ str((answers or {}).get(str(task_id), "")).strip()
457
+ )
458
  updated = dict(answers or {})
459
  updated[str(task_id)] = answer
460
  dataframe = review_dataframe(questions, updated)
461
+ action_message = (
462
+ "A resposta anterior foi substituída pela nova resposta."
463
+ if had_previous_answer
464
+ else "A primeira resposta desta questão foi salva."
465
+ )
466
  return (
467
  answer,
468
  updated,
469
+ f"Questão executada. {action_message} "
470
+ "Revise o conteúdo antes de avançar.",
471
  progress_summary(questions, updated),
472
  readiness_summary(dataframe),
473
  dataframe,
 
484
  )
485
 
486
 
487
+ def run_all_evaluation_questions(
488
+ profile: gr.OAuthProfile | None, questions: list, answers: dict
489
+ ):
490
+ """Executa todas as questões carregadas e reúne as respostas para revisão."""
491
+ if not profile:
492
+ dataframe = review_dataframe(questions, answers)
493
+ return (
494
+ answers or {},
495
+ "Faça login no Hugging Face primeiro.",
496
+ progress_summary(questions, answers),
497
+ readiness_summary(dataframe),
498
+ dataframe,
499
+ )
500
+
501
+ if not questions:
502
+ dataframe = review_dataframe(questions, answers)
503
+ return (
504
+ answers or {},
505
+ "Primeiro clique em 'Carregar as 20 questões'.",
506
+ progress_summary(questions, answers),
507
+ readiness_summary(dataframe),
508
+ dataframe,
509
+ )
510
+
511
+ try:
512
+ agent = BasicAgent()
513
+ except Exception as exc:
514
+ dataframe = review_dataframe(questions, answers)
515
+ return (
516
+ answers or {},
517
+ f"Erro ao inicializar o agente: {exc}",
518
+ progress_summary(questions, answers),
519
+ readiness_summary(dataframe),
520
+ dataframe,
521
+ )
522
+
523
+ updated = dict(answers or {})
524
+ failures = 0
525
+ for item in questions:
526
+ task_id = str(item.get("task_id", "")).strip()
527
+ question = str(item.get("question", "")).strip()
528
+ if not task_id or not question:
529
+ continue
530
+ try:
531
+ updated[task_id] = agent(question, task_id)
532
+ except Exception as exc:
533
+ updated[task_id] = f"ERROR: {exc}"
534
+ failures += 1
535
+
536
+ dataframe = review_dataframe(questions, updated)
537
+ status = (
538
+ f"Execução das {len(questions)} questões concluída. "
539
+ f"Falhas encontradas: {failures}. Revise as respostas antes de enviar."
540
+ )
541
+ return (
542
+ updated,
543
+ status,
544
+ progress_summary(questions, updated),
545
+ readiness_summary(dataframe),
546
+ dataframe,
547
+ )
548
+
549
+
550
  def fetch_random_question():
551
  """Busca somente uma questão oficial aleatória, sem executar ou enviar."""
552
  try:
 
810
  evaluation_answers = gr.State({})
811
  current_task_id = gr.State("")
812
 
813
+ with gr.Row():
814
+ load_questions_button = gr.Button(
815
+ "Carregar as 20 questões", variant="secondary"
816
+ )
817
+ run_all_button = gr.Button(
818
+ "Executar as 20 questões", variant="primary"
819
+ )
820
  question_selector = gr.Dropdown(
821
  label="Escolha a questão",
822
  choices=[],
 
837
  )
838
  with gr.Row():
839
  run_current_button = gr.Button(
840
+ "Responder novamente esta questão", variant="primary"
841
  )
842
  save_answer_button = gr.Button("Salvar resposta revisada")
843
 
 
877
  results_table,
878
  ],
879
  )
880
+ run_all_button.click(
881
+ fn=run_all_evaluation_questions,
882
+ inputs=[evaluation_questions, evaluation_answers],
883
+ outputs=[
884
+ evaluation_answers,
885
+ run_status,
886
+ evaluation_progress,
887
+ evaluation_readiness,
888
+ results_table,
889
+ ],
890
+ )
891
  question_selector.change(
892
  fn=select_evaluation_question,
893
  inputs=[