File size: 4,843 Bytes
af7959d e01620b 161967b af7959d 0c7edbd af7959d 0c7edbd 161967b 0c7edbd e01620b 0c7edbd 98db947 e01620b 0c7edbd e01620b d008f82 0c7edbd d008f82 e01620b 61d05d6 98db947 0c7edbd 98db947 0c7edbd e01620b 61d05d6 98db947 e01620b 98db947 0c7edbd 98db947 d008f82 98db947 0c7edbd af7959d e01620b 0c7edbd af7959d e01620b 0c7edbd af7959d e01620b d008f82 0c7edbd af7959d 0c7edbd e01620b 161967b e01620b d008f82 e01620b 0c7edbd d008f82 af7959d 0c7edbd e01620b d008f82 0c7edbd d008f82 af7959d e01620b 0c7edbd e01620b af7959d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
import gradio as gr
from back_end import next_annotation, submit_correction, enable_buttons
from utils import compute_diff, LANGS
## COMPONENTS
with gr.Blocks() as demo:
gr.Markdown(
"""# Ingredients Spellcheck π
### Review the Spellcheck corrections. Your precious feedback will be integrated to the Open Food Facts database!
### Instructions:
* You are provided the original list of ingredients text as stored in the Open Food Facts (OFF) database, the Spellcheck prediction, and optionally a picture of the product.
* Your task, if you accept π£, is to review the Spellcheck prediction by either validating or correcting it.
* The picture is only here to help you during the annotation as a reference. It can happen that the language of the text and the picture are different. **Keep calm and focus on the text.**
* It can happen that the Producer has made a mistake on the product packaging. Since we parse the list of ingredients to extract its information, it would be preferable if you fix the typo.
* Deleted whitespaces are indicated as `#` and additional whitespaces are indicated as `^`.
### Important:
* Authenticate yourself using your Open Food Facts username and password to add modifications to a product. If you're not registered yet, you can do so [here](https://world.openfoodfacts.org/cgi/user.pl)!
"""
)
with gr.Row():
with gr.Column():
insight_id = gr.Textbox(
label="Insight Id",
visible=False,
)
with gr.Row():
off_username = gr.Textbox(
label="OFF Username",
)
off_password = gr.Textbox(
label="OFF Password",
type="password",
)
lang = gr.Dropdown(
choices=LANGS.keys(),
value="All",
label="Language",
info="Optional: Filter a language.",
)
# Saved to detect change from annotator
model_correction = gr.Text(visible=False)
original = gr.Textbox(
label="Original",
info="List of ingredients stored in the database.",
interactive=False, # Make this text box uneditable
lines=3,
)
annotator_correction = gr.Textbox(
label="Spellcheck Correction",
info="Is it correct",
interactive=True, # Make this text box editable
lines=3,
)
# Diff Display using HighlightedText
diff_display = gr.HighlightedText(
label="Difference Between Original and Corrected Text",
combine_adjacent=True,
show_legend=True,
color_map={"+": "green", "-": "red"},
)
with gr.Column():
url = gr.Textbox(label="Product page", show_copy_button=True)
image = gr.Image()
# Validate button to move to next annotation
with gr.Row():
validate_button = gr.Button("Validate", interactive=False)
skip_button = gr.Button("Skip", interactive=False)
## COMPONENT INTERACTIONS
validate_button.click(
submit_correction,
inputs=[
insight_id,
annotator_correction,
model_correction,
off_username,
off_password,
lang,
],
outputs=[insight_id, original, model_correction, annotator_correction, image, url],
)
skip_button.click(
next_annotation,
inputs=[lang],
outputs=[insight_id, original, model_correction, annotator_correction, image, url],
)
annotator_correction.change(
compute_diff, # Call diff function
inputs=[original, annotator_correction],
outputs=diff_display,
)
off_username.change(
enable_buttons,
inputs=[off_username, off_password],
outputs=[validate_button, skip_button],
)
off_password.change(
enable_buttons,
inputs=[off_username, off_password],
outputs=[validate_button, skip_button],
)
lang.change(
next_annotation,
inputs=[lang],
outputs=[insight_id, original, model_correction, annotator_correction, image, url],
)
# Load the first set of texts when the demo starts
demo.load(
next_annotation,
inputs=[],
outputs=[
insight_id,
original,
model_correction,
annotator_correction,
image,
url,
],
)
if __name__ == "__main__":
demo.launch()
|