| state_user = gr.State(lambda: {"user_id": str(uuid.uuid4())[:8], "index": 0}) |
| state_candidates_info = gr.State([]) |
|
|
| with gr.Row(): |
| md_instruction = gr.Markdown("Loading...") |
|
|
| with gr.Row(): |
| with gr.Column(scale=1): |
| |
| img_origin = gr.Image(label="Reference (参考原图)", interactive=False, height=400, format="jpeg") |
| |
| with gr.Column(scale=2): |
| gallery_candidates = gr.Gallery( |
| label="Candidates (候选结果)", |
| columns=[2], |
| height="auto", |
| object_fit="contain", |
| interactive=False, |
| format="jpeg" |
| ) |
| |
| gr.Markdown("👇 **请在下方勾选您认为最好的结果(可多选):**") |
| |
| checkbox_options = gr.CheckboxGroup( |
| choices=[], |
| label="您的选择", |
| info="对应上方图片的标签 (Option A, B...)" |
| ) |
| |
| with gr.Row(): |
| btn_submit = gr.Button("🚀 提交 (Submit)", variant="primary") |
| btn_none = gr.Button("🚫 都不满意 (None)", variant="stop") |
|
|
| md_end = gr.Markdown(visible=False) |
|
|
| demo.load( |
| fn=get_next_question, |
| inputs=[state_user], |
| outputs=[img_origin, gallery_candidates, checkbox_options, md_instruction, btn_submit, btn_none, md_end, state_user, state_candidates_info] |
| ) |
|
|
| btn_submit.click( |
| fn=lambda s, c, o: save_and_next(s, c, o, is_none=False), |
| inputs=[state_user, state_candidates_info, checkbox_options], |
| outputs=[img_origin, gallery_candidates, checkbox_options, md_instruction, btn_submit, btn_none, md_end, state_user, state_candidates_info] |
| ) |
|
|
| btn_none.click( |
| fn=lambda s, c, o: save_and_next(s, c, o, is_none=True), |
| inputs=[state_user, state_candidates_info, checkbox_options], |
| outputs=[img_origin, gallery_candidates, checkbox_options, md_instruction, btn_submit, btn_none, md_end, state_user, state_candidates_info] |
| ) |