File size: 2,229 Bytes
fc85e7c ec819d9 161d75f 869adb6 ec819d9 21dae66 fc85e7c 869adb6 fc85e7c 21dae66 fc85e7c 21dae66 fc85e7c 21dae66 fc85e7c 21dae66 fc85e7c 869adb6 baec762 |
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 |
import gradio as gr
from dotenv import load_dotenv
import os
from typing import List
from shapely.geometry import Point
from physical.physical_checkbox import *
from physical.physical_boxes_define import gdf
from utils.utils_visible import set_visible
from validation_submission.utils_individual import add_data_to_individual
load_dotenv()
PATH_ASSETS = os.getenv("PATH_ASSETS")
# Function to find the matching bounding box for a given point and return the image with boxes
def find_bounding_box(evt: gr.SelectData, img, section: str, mode: str):
x, y = evt.index[0], evt.index[1]
point = Point(x, y)
match = gdf[gdf.contains(point)]
if not match.empty:
matched_box = match.iloc[0]["name"]
(
checkbox_beak,
text_beak,
checkbox_body,
text_body,
checkbox_feathers,
text_feathers,
checkbox_head,
text_head,
checkbox_legs,
text_legs,
) = process_body_parts(section, mode, matched_box)
else:
matched_box = None
(
checkbox_beak,
text_beak,
checkbox_body,
text_body,
checkbox_feathers,
text_feathers,
checkbox_head,
text_head,
checkbox_legs,
text_legs,
) = process_body_parts(section, mode, matched_box)
return (
checkbox_beak,
text_beak,
checkbox_body,
text_body,
checkbox_feathers,
text_feathers,
checkbox_head,
text_head,
checkbox_legs,
text_legs,
)
# Gradio app
def create_bird_anatomy(visible, section: str):
# Draw bounding boxes on the image
img_with_boxes = gr.Image(
value=PATH_ASSETS + "images/bird_boxed.png",
show_label=False,
height="600px",
elem_id=section,
visible=visible,
)
return img_with_boxes
def show_physical(choice, section: str, individual):
visible = set_visible(choice)
physical_boxes = create_bird_anatomy(visible, section)
individual = add_data_to_individual("physical_radio", choice, individual)
return physical_boxes, individual
|