Spaces:
Running
Running
import gradio as gr | |
from gradio_image_annotation import image_annotator | |
example_annotation = { | |
"image": "background.png", | |
"boxes": [], | |
} | |
# def add_label(annotations, label_text): | |
# if annotations["boxes"]: | |
# # 修改最后一个 box 的 label | |
# annotations["boxes"][-1]["label"] = label_text | |
# return annotations | |
def get_boxes_json(annotations): | |
print(annotations) | |
image = annotations["image"] | |
width = image.shape[1] | |
height = image.shape[0] | |
boxes = annotations["boxes"] | |
for box in boxes: | |
box["xmin"] = box["xmin"] / width | |
box["xmax"] = box["xmax"] / width | |
box["ymin"] = box["ymin"] / height | |
box["ymax"] = box["ymax"] / height | |
return annotations["boxes"] | |
with gr.Blocks() as demo: | |
with gr.Tab("DreamRenderer", id="DreamRenderer"): | |
annotator = image_annotator(example_annotation, | |
height=512, | |
width=512 | |
) | |
button_get = gr.Button("Get bounding boxes") | |
json_boxes = gr.JSON() | |
button_get.click(get_boxes_json, annotator, json_boxes) | |
if __name__ == "__main__": | |
demo.launch(share=True) |