Spaces:
Running
Running
Commit
·
3928c4d
1
Parent(s):
f4ef5b4
Enhance flagging functionality in app.py and flagging.py by adding a subscription option and improving metadata handling for user information.
Browse files- app.py +11 -6
- flagging.py +7 -1
app.py
CHANGED
|
@@ -69,18 +69,22 @@ def inference(image):
|
|
| 69 |
|
| 70 |
|
| 71 |
def flag_img_input(
|
| 72 |
-
image: gr.Image,
|
|
|
|
|
|
|
|
|
|
| 73 |
):
|
| 74 |
"""Wrapper for flagging"""
|
| 75 |
-
logger.info("Flagging image - name: %s, email: %s",
|
| 76 |
|
| 77 |
# Decode blob data if necessary
|
| 78 |
if is_blob_data(image):
|
| 79 |
image = decode_blob_data(image)
|
| 80 |
|
| 81 |
metadata = {
|
| 82 |
-
"name":
|
| 83 |
-
"email":
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
hf_writer.flag([image], metadata=metadata)
|
|
@@ -153,10 +157,11 @@ with gr.Blocks(theme=theme, css=css, title="SEA.AI Vision Demo") as demo:
|
|
| 153 |
flag: gr.Button(FLAG_TXT, interactive=True, visible=visible),
|
| 154 |
notice: gr.Markdown(value=NOTICE, visible=visible),
|
| 155 |
}
|
| 156 |
-
|
| 157 |
# add hidden textbox for name and email (hacky but well...)
|
| 158 |
name = gr.Textbox(label="name", visible=False, value="anonymous")
|
| 159 |
email = gr.Textbox(label="email", visible=False, value="[email protected]")
|
|
|
|
| 160 |
|
| 161 |
# This needs to be called prior to the first call to callback.flag()
|
| 162 |
hf_writer.setup([img_input], "flagged")
|
|
@@ -169,7 +174,7 @@ with gr.Blocks(theme=theme, css=css, title="SEA.AI Vision Demo") as demo:
|
|
| 169 |
show_api=False,
|
| 170 |
).then(
|
| 171 |
flag_img_input,
|
| 172 |
-
[img_input, name, email],
|
| 173 |
[],
|
| 174 |
preprocess=False,
|
| 175 |
show_api=True,
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
def flag_img_input(
|
| 72 |
+
image: gr.Image,
|
| 73 |
+
name_: str = "misdetection",
|
| 74 |
+
email_: str = "[email protected]",
|
| 75 |
+
subscribe_: bool = False,
|
| 76 |
):
|
| 77 |
"""Wrapper for flagging"""
|
| 78 |
+
logger.info("Flagging image - name: %s, email: %s, subscribe: %s", name_, email_, subscribe_)
|
| 79 |
|
| 80 |
# Decode blob data if necessary
|
| 81 |
if is_blob_data(image):
|
| 82 |
image = decode_blob_data(image)
|
| 83 |
|
| 84 |
metadata = {
|
| 85 |
+
"name": name_,
|
| 86 |
+
"email": email_,
|
| 87 |
+
"subscribe": subscribe_,
|
| 88 |
}
|
| 89 |
|
| 90 |
hf_writer.flag([image], metadata=metadata)
|
|
|
|
| 157 |
flag: gr.Button(FLAG_TXT, interactive=True, visible=visible),
|
| 158 |
notice: gr.Markdown(value=NOTICE, visible=visible),
|
| 159 |
}
|
| 160 |
+
|
| 161 |
# add hidden textbox for name and email (hacky but well...)
|
| 162 |
name = gr.Textbox(label="name", visible=False, value="anonymous")
|
| 163 |
email = gr.Textbox(label="email", visible=False, value="[email protected]")
|
| 164 |
+
subscribe = gr.Checkbox(label="subscribe", value=False, visible=False)
|
| 165 |
|
| 166 |
# This needs to be called prior to the first call to callback.flag()
|
| 167 |
hf_writer.setup([img_input], "flagged")
|
|
|
|
| 174 |
show_api=False,
|
| 175 |
).then(
|
| 176 |
flag_img_input,
|
| 177 |
+
[img_input, name, email, subscribe],
|
| 178 |
[],
|
| 179 |
preprocess=False,
|
| 180 |
show_api=True,
|
flagging.py
CHANGED
|
@@ -275,8 +275,14 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
|
|
| 275 |
)
|
| 276 |
else:
|
| 277 |
row.append("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
for key, value in metadata.items():
|
| 279 |
-
features[key] = {"dtype":
|
| 280 |
row.append(value)
|
| 281 |
return features, row
|
| 282 |
|
|
|
|
| 275 |
)
|
| 276 |
else:
|
| 277 |
row.append("")
|
| 278 |
+
type_to_dtype = {
|
| 279 |
+
bool: "boolean",
|
| 280 |
+
str: "string",
|
| 281 |
+
int: "integer",
|
| 282 |
+
float: "float",
|
| 283 |
+
}
|
| 284 |
for key, value in metadata.items():
|
| 285 |
+
features[key] = {"dtype": type_to_dtype[type(value)], "_type": "Value"}
|
| 286 |
row.append(value)
|
| 287 |
return features, row
|
| 288 |
|