Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ import gradio as gr
|
|
7 |
from datasets import Dataset, load_dataset
|
8 |
import logging
|
9 |
import pandas as pd
|
10 |
-
import os
|
11 |
from dotenv import load_dotenv
|
12 |
|
13 |
load_dotenv()
|
@@ -16,12 +15,15 @@ logging.basicConfig(level=logging.INFO)
|
|
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.
|
@@ -33,12 +35,16 @@ def non_validated_samples() -> Generator[tuple[str, str, str], None, None]:
|
|
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:
|
44 |
gr.Markdown("""
|
@@ -79,10 +85,7 @@ def main():
|
|
79 |
)
|
80 |
save_results_btn.click(fn=save_results)
|
81 |
|
82 |
-
auth = [
|
83 |
-
("admin", os.environ["ADMIN_PASSWORD"]),
|
84 |
-
("annika", os.environ["ANNIKA_PASSWORD"]),
|
85 |
-
]
|
86 |
demo.launch(auth=auth)
|
87 |
|
88 |
|
@@ -91,7 +94,7 @@ def save_results() -> None:
|
|
91 |
logger.info("Saving results...")
|
92 |
gr.Info(message="Saving results...")
|
93 |
Dataset.from_pandas(df, preserve_index=False).push_to_hub(
|
94 |
-
repo_id="alexandrainst/foqa"
|
95 |
)
|
96 |
gr.Info(message="Saved results!")
|
97 |
logger.info("Saved results.")
|
@@ -179,4 +182,4 @@ def assign_incorrect_answer(
|
|
179 |
|
180 |
|
181 |
if __name__ == "__main__":
|
182 |
-
main()
|
|
|
7 |
from datasets import Dataset, load_dataset
|
8 |
import logging
|
9 |
import pandas as pd
|
|
|
10 |
from dotenv import load_dotenv
|
11 |
|
12 |
load_dotenv()
|
|
|
15 |
logger = logging.getLogger("foqa")
|
16 |
|
17 |
|
18 |
+
dataset = load_dataset("alexandrainst/foqa", split="train")
|
|
|
|
|
19 |
assert isinstance(dataset, Dataset)
|
20 |
df = pd.DataFrame(dataset.to_pandas())
|
21 |
|
22 |
+
logger.info(
|
23 |
+
f"Loaded dataset with {len(df)} samples, where "
|
24 |
+
f"{len(df) - df.validation.isnull().sum()} are validated."
|
25 |
+
)
|
26 |
+
|
27 |
|
28 |
def non_validated_samples() -> Generator[tuple[str, str, str], None, None]:
|
29 |
"""Iterate over non-validated samples in the FoQA dataset.
|
|
|
35 |
if sample.validation is None:
|
36 |
yield str(idx), sample.question, sample.answers["text"][0]
|
37 |
|
38 |
+
# Yield example at the end
|
39 |
+
sample = df.iloc[0]
|
40 |
+
yield str(0), sample.question, sample.answers["text"][0]
|
41 |
+
|
42 |
|
43 |
itr = non_validated_samples()
|
44 |
|
45 |
|
46 |
def main():
|
47 |
+
idx, question, answer = next(itr, ("All samples are validated!", "", ""))
|
48 |
|
49 |
with gr.Blocks(theme="monochrome", title="FoQA validation") as demo:
|
50 |
gr.Markdown("""
|
|
|
85 |
)
|
86 |
save_results_btn.click(fn=save_results)
|
87 |
|
88 |
+
auth = [("admin", os.environ["ADMIN_PASSWORD"])]
|
|
|
|
|
|
|
89 |
demo.launch(auth=auth)
|
90 |
|
91 |
|
|
|
94 |
logger.info("Saving results...")
|
95 |
gr.Info(message="Saving results...")
|
96 |
Dataset.from_pandas(df, preserve_index=False).push_to_hub(
|
97 |
+
repo_id="alexandrainst/foqa"
|
98 |
)
|
99 |
gr.Info(message="Saved results!")
|
100 |
logger.info("Saved results.")
|
|
|
182 |
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
+
main()
|