import os import requests from PIL import Image from io import BytesIO def download_example_images(): """ Downloads example images for the application. """ # Create directory if it doesn't exist os.makedirs('example_images', exist_ok=True) # Example image URLs example_images = { 'tomato_early_blight.jpg': 'https://www.gardeningknowhow.com/wp-content/uploads/2019/05/tomato-early-blight.jpg', 'apple_scab.jpg': 'https://www.planetnatural.com/wp-content/uploads/2012/12/apple-scab-1.jpg', 'corn_rust.jpg': 'https://extension.umn.edu/sites/extension.umn.edu/files/styles/large/public/corn-rust-JosieMontgomery.jpg' } # Download each image for filename, url in example_images.items(): try: response = requests.get(url) if response.status_code == 200: img = Image.open(BytesIO(response.content)) img.save(os.path.join('example_images', filename)) print(f"Downloaded {filename}") else: print(f"Failed to download {filename}: HTTP {response.status_code}") except Exception as e: print(f"Error downloading {filename}: {e}") print("Example images download complete") if __name__ == "__main__": download_example_images()