File size: 1,424 Bytes
df20613 beb3e34 b73b4e1 df20613 26b8b00 31b5ef1 26b8b00 31b5ef1 854f030 e895b3f cf54ad5 f9fb74c cf54ad5 beb3e34 854f030 ca45677 854f030 ca45677 aca188e |
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 |
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",
)
#"# :dart: Streamlit Image Coordinates: Image Update"
if "points" not in st.session_state:
st.session_state["points"] = []
#"## Click on image"
with ds[0]['image'] as img:
draw = ImageDraw.Draw(img)
def get_ellipse_coords(point):# tuple[int, int]) -> tuple[int, int, int, int]):
center = point
radius = 32
return (
center[0] - radius,
center[1] - radius,
center[0] + radius,
center[1] + radius,
)
# Draw an ellipse at each coordinate in points
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') |