saattrupdan commited on
Commit
c2ee91b
·
1 Parent(s): f74f2ff

fix: Load non-validated examples properly

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -16,27 +16,28 @@ logging.basicConfig(level=logging.INFO)
16
  logger = logging.getLogger("foqa")
17
 
18
 
19
- # Load the FoQA dataset in the global scope, as it is used in multiple functions
20
- foqa = load_dataset(
21
  "alexandrainst/foqa", split="train", token=os.getenv("HF_HUB_TOKEN")
22
  )
23
- assert isinstance(foqa, Dataset)
24
- df = foqa.to_pandas()
25
- assert isinstance(df, pd.DataFrame)
26
 
27
 
28
- def main():
29
- def non_validated_samples() -> Generator[tuple[str, str, str], None, None]:
30
- """Iterate over non-validated samples in the FoQA dataset.
 
 
 
 
 
 
31
 
32
- Yields:
33
- A tuple (idx, question, answer) of a non-validated sample.
34
- """
35
- for idx, sample in df.iterrows():
36
- if sample.validation is None:
37
- yield str(idx), sample.question, sample.answers["text"][0]
38
 
39
- itr = non_validated_samples()
 
 
 
40
  idx, question, answer = next(itr)
41
 
42
  with gr.Blocks(theme="monochrome", title="FoQA validation") as demo:
@@ -58,7 +59,7 @@ def main():
58
  with gr.Column():
59
  correct_btn = gr.Button(value="Correct")
60
  incorrect_btn = gr.Button(value="Incorrect")
61
- save_results_btn = gr.Button(value="Save results")
62
 
63
  correct_btn.click(
64
  fn=partial(assign_correct, itr=itr),
@@ -70,7 +71,7 @@ def main():
70
  inputs=[idx_box, question_box, answer_box],
71
  outputs=[idx_box, question_box, answer_box],
72
  )
73
- save_results_btn.click(fn=partial(save_results))
74
 
75
  auth = [
76
  ("admin", os.environ["ADMIN_PASSWORD"]),
@@ -79,7 +80,7 @@ def main():
79
  demo.launch(auth=auth)
80
 
81
 
82
- def save_results() -> None:
83
  """Update the FoQA dataset with the validation status of a sample."""
84
  logger.info("Saving results...")
85
  gr.Info(message="Saving results...")
 
16
  logger = logging.getLogger("foqa")
17
 
18
 
19
+ dataset = load_dataset(
 
20
  "alexandrainst/foqa", split="train", token=os.getenv("HF_HUB_TOKEN")
21
  )
22
+ assert isinstance(dataset, Dataset)
23
+ df = pd.DataFrame(dataset.to_pandas())
 
24
 
25
 
26
+ def non_validated_samples() -> Generator[tuple[str, str, str], None, None]:
27
+ """Iterate over non-validated samples in the FoQA dataset.
28
+
29
+ Yields:
30
+ A tuple (idx, question, answer) of a non-validated sample.
31
+ """
32
+ for idx, sample in df.iterrows():
33
+ if sample.validation is None:
34
+ yield str(idx), sample.question, sample.answers["text"][0]
35
 
 
 
 
 
 
 
36
 
37
+ itr = non_validated_samples()
38
+
39
+
40
+ def main():
41
  idx, question, answer = next(itr)
42
 
43
  with gr.Blocks(theme="monochrome", title="FoQA validation") as demo:
 
59
  with gr.Column():
60
  correct_btn = gr.Button(value="Correct")
61
  incorrect_btn = gr.Button(value="Incorrect")
62
+ load_results_btn = gr.Button(value="Load results")
63
 
64
  correct_btn.click(
65
  fn=partial(assign_correct, itr=itr),
 
71
  inputs=[idx_box, question_box, answer_box],
72
  outputs=[idx_box, question_box, answer_box],
73
  )
74
+ load_results_btn.click(fn=load_results)
75
 
76
  auth = [
77
  ("admin", os.environ["ADMIN_PASSWORD"]),
 
80
  demo.launch(auth=auth)
81
 
82
 
83
+ def load_results() -> None:
84
  """Update the FoQA dataset with the validation status of a sample."""
85
  logger.info("Saving results...")
86
  gr.Info(message="Saving results...")