mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
flagging is working
This commit is contained in:
parent
1587f1ab4b
commit
def76d1cbd
2
.gitignore
vendored
2
.gitignore
vendored
@ -20,7 +20,7 @@ gradio/templates/frontend/static
|
||||
*.db
|
||||
*.sqlite3
|
||||
gradio/launches.json
|
||||
flagged
|
||||
flagged/*
|
||||
|
||||
# Tests
|
||||
.coverage
|
||||
|
23672
frontend/package-lock.json
generated
23672
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -209,38 +209,40 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
||||
self.log_file = os.path.join(self.dataset_dir, "data.csv")
|
||||
|
||||
def flag(self, interface, input_data, output_data, flag_option=None,
|
||||
flag_index=None, username=None, path=None):
|
||||
flag_index=None, username=None, path=None):
|
||||
# Note flag_index, username, path are not currently used
|
||||
is_new = not os.path.exists(self.log_file)
|
||||
with open(self.log_file, "a", newline="") as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
|
||||
# Generate the headers
|
||||
headers = [interface["label"] for interface in interface.config["input_components"]]
|
||||
headers += [interface["label"] for interface in interface.config["output_components"]]
|
||||
if interface.flagging_options is not None:
|
||||
headers.append("flag")
|
||||
if is_new:
|
||||
headers = [interface["label"] for interface in interface.config["input_components"]]
|
||||
headers += [interface["label"] for interface in interface.config["output_components"]]
|
||||
if interface.flagging_options is not None:
|
||||
headers.append("flag")
|
||||
writer.writerow(headers)
|
||||
|
||||
# Generate the row corresponding to the flagged sample
|
||||
csv_data = []
|
||||
for i, input in enumerate(interface.input_components):
|
||||
csv_data.append(input.save_flagged(self.flagging_dir, interface.config["input_components"][i]["label"], input_data[i], None))
|
||||
csv_data.append(input.save_flagged(self.dataset_dir, interface.config["input_components"][i]["label"], input_data[i], None))
|
||||
for i, output in enumerate(interface.output_components):
|
||||
csv_data.append(output.save_flagged(self.flagging_dir, interface.config["output_components"][i]["label"], output_data[i], None) if
|
||||
csv_data.append(output.save_flagged(self.dataset_dir, interface.config["output_components"][i]["label"], output_data[i], None) if
|
||||
output_data[i] is not None else "")
|
||||
if flag_option is not None:
|
||||
csv_data.append(flag_option)
|
||||
|
||||
# Write the rows
|
||||
if is_new:
|
||||
writer.writerow(headers)
|
||||
writer.writerow(csv_data)
|
||||
|
||||
# push the repo
|
||||
self.repo.push_to_hub()
|
||||
|
||||
# return number of samples in dataset
|
||||
with open(self.log_file, "r") as csvfile:
|
||||
line_count = len([None for row in csv.reader(csvfile)]) - 1
|
||||
|
||||
# push the repo
|
||||
self.repo.push_to_hub(
|
||||
commit_message="Flagged sample #{}".format(line_count))
|
||||
|
||||
return line_count
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.baff0885.css",
|
||||
"main.css": "/static/css/main.54d5b21c.css",
|
||||
"main.js": "/static/bundle.js",
|
||||
"index.html": "/index.html",
|
||||
"static/media/api-logo.b3893a52.svg": "/static/media/api-logo.b3893a52.svg",
|
||||
"static/media/arrow-left.e497f657.svg": "/static/media/arrow-left.e497f657.svg",
|
||||
"static/media/arrow-right.ea6059fd.svg": "/static/media/arrow-right.ea6059fd.svg",
|
||||
"static/media/clear.33f9b5f3.svg": "/static/media/clear.33f9b5f3.svg",
|
||||
"static/media/edit.44bd4fe1.svg": "/static/media/edit.44bd4fe1.svg",
|
||||
"static/media/logo.411acfd1.svg": "/static/media/logo.411acfd1.svg",
|
||||
"static/media/api-logo.93f17adb.svg": "/static/media/api-logo.93f17adb.svg",
|
||||
"static/media/arrow-left.794a4706.svg": "/static/media/arrow-left.794a4706.svg",
|
||||
"static/media/arrow-right.5a7d4ada.svg": "/static/media/arrow-right.5a7d4ada.svg",
|
||||
"static/media/clear.85cf6de8.svg": "/static/media/clear.85cf6de8.svg",
|
||||
"static/media/edit.c6b7d6f7.svg": "/static/media/edit.c6b7d6f7.svg",
|
||||
"static/media/logo.36a8f455.svg": "/static/media/logo.36a8f455.svg",
|
||||
"static/media/logo_loading.e93acd82.jpg": "/static/media/logo_loading.e93acd82.jpg"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/bundle.css",
|
||||
"static/css/main.baff0885.css",
|
||||
"static/css/main.54d5b21c.css",
|
||||
"static/bundle.js"
|
||||
]
|
||||
}
|
@ -8,4 +8,4 @@
|
||||
window.gradio_config = {{ config|tojson }};
|
||||
} catch (e) {
|
||||
window.gradio_config = {"mode": "dev"};
|
||||
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.baff0885.css" rel="stylesheet"></head><body style="height:100%;margin:0;padding:0"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>
|
||||
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.54d5b21c.css" rel="stylesheet"></head><body style="height:100%;margin:0;padding:0"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>
|
Loading…
x
Reference in New Issue
Block a user