import streamlit as st from PIL import Image import numpy as np st.title("Tree Counter App") # Upload image via Streamlit uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) if uploaded_file is not None: # Open the image img = Image.open(uploaded_file) st.image(img, caption="Uploaded Image.", use_column_width=True) # Check image dimensions width, height = img.size if width > 1024 or height > 1024: st.error("Image is too large. Please crop it.") else: # Simulate tree detection using random number trees = np.random.randint(0, 100) st.success(f"Number of Trees: {trees}") # Image cropping functionality if uploaded_file is not None and st.button("Crop Image to 1024x1024"): cropped_img = img.crop((0, 0, min(1024, img.width), min(1024, img.height))) st.image(cropped_img, caption="Cropped Image.", use_column_width=True) cropped_img.save("cropped_image.jpg") st.success("Image cropped successfully.")