File size: 2,690 Bytes
6911988
2be323a
6911988
 
2be323a
 
ed2bf63
6911988
2be323a
 
998a811
 
 
 
6911988
2be323a
ed2bf63
 
 
 
 
2be323a
b9f0fb6
2be323a
 
 
ac515ce
998a811
b9f0fb6
998a811
e338f26
998a811
ed2bf63
a0f7b41
 
 
ed2bf63
ac515ce
ed2bf63
03b5da2
ed2bf63
998a811
 
 
ac515ce
2be323a
ed2bf63
 
 
 
 
a0f7b41
ed2bf63
 
 
 
 
 
 
 
 
 
 
 
 
6911988
 
 
 
ed2bf63
2be323a
ed2bf63
 
 
 
 
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
import os
import gradio as gr
import pandas as pd
from config import OUTPUT_DIR
from .annotation_logic import (
    save_and_next, previous_image, delete_and_next, save_and_exit,
    get_current_image_path, get_annotation_for_image,
    refresh_image_list, switch_tile_csv
)


def enable_buttons():
    return [gr.Button(interactive=True)]*4

def get_annotation_widgets(selected_tile_state):
    message = gr.Markdown("", visible=False)
    image_path_display = gr.Markdown(
        value=get_current_image_path() or "No image loaded",
        elem_id="image_path"
    )
    progress_display = gr.Markdown(value="No images loaded", elem_id="progress_display")
    img = gr.Image(type="filepath", value=get_current_image_path(), label="Blob")
    txt = gr.Textbox(label="Transcription", elem_id="transcription_box",autofocus=True)
    hint = gr.Markdown("*If there are multiple street names in the image, please separate them with commas.*")

    with gr.Row():
        refresh_btn = gr.Button("Retrieve Images") 
        prev_btn = gr.Button("Previous", interactive=False)
        next_btn = gr.Button("Save & Next", variant="primary", interactive=False)
        del_btn = gr.Button("Delete & Next", variant="stop", interactive=False)
        #exit_btn = gr.Button("Save & Exit", variant="secondary")
        download_btn = gr.Button("Download Annotations", interactive=False)

    with gr.Row():
        download_file = gr.File(label="Download CSV", interactive=False)  

    # === Button wiring with progress_display as last output ===
    refresh_btn.click(
        fn=refresh_image_list,
        inputs=[selected_tile_state],
        outputs=[img, txt, message, image_path_display, progress_display]
    ).then(
        fn=enable_buttons,
        outputs=[prev_btn,next_btn,del_btn,download_btn]
    )

    next_btn.click(
        save_and_next,
        inputs=txt,
        outputs=[img, txt, message, image_path_display, progress_display]
    )

    prev_btn.click(
        previous_image,
        outputs=[img, txt, message, image_path_display, progress_display]
    )

    del_btn.click(
        delete_and_next,
        outputs=[img, txt, message, image_path_display, progress_display]
    )

    #exit_btn.click(save_and_exit, inputs=txt, outputs=[img, txt, message, image_path_display, progress_display])

    download_btn.click(
        #lambda: get_current_annotations_path(),
        fn=lambda selected_tile: switch_tile_csv(selected_tile),
        inputs=[selected_tile_state],
        outputs=[download_file]
    )

    return [
        message, image_path_display, progress_display, img, txt, hint,
        refresh_btn, prev_btn, next_btn, del_btn
        #, exit_btn
    ]