|
import streamlit as st |
|
from PIL import Image, ImageDraw |
|
|
|
from streamlit_image_coordinates import streamlit_image_coordinates |
|
|
|
|
|
from datasets import load_dataset |
|
|
|
ds = load_dataset("Circularmachines/batch_indexing_machine_100_small_imgs", split="train") |
|
|
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config( |
|
page_title="Streamlit Image Coordinates: Image Update", |
|
page_icon="🎯", |
|
layout="wide", |
|
) |
|
|
|
|
|
|
|
if "points" not in st.session_state: |
|
st.session_state["points"] = [] |
|
|
|
|
|
|
|
|
|
|
|
with ds[0]['image'] as img: |
|
draw = ImageDraw.Draw(img) |
|
|
|
def get_ellipse_coords(point): |
|
center = point |
|
radius = 32 |
|
return ( |
|
center[0] - radius, |
|
center[1] - radius, |
|
center[0] + radius, |
|
center[1] + radius, |
|
) |
|
|
|
|
|
|
|
for point in st.session_state["points"]: |
|
coords = get_ellipse_coords(point) |
|
draw.rectangle(coords, outline="green",width=2) |
|
|
|
value = streamlit_image_coordinates(img, key="pil") |
|
|
|
if value is not None: |
|
point = value["x"], value["y"] |
|
|
|
if point not in st.session_state["points"]: |
|
st.session_state["points"]=[point] |
|
st.experimental_rerun() |
|
|
|
|
|
if st.button('Say hello'): |
|
st.write('Why hello there') |
|
else: |
|
st.write('Goodbye') |