histOSM / annotation_tab /annotation_setup.py
muk42's picture
fix
03b5da2
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
]