File size: 1,330 Bytes
a4e3080 |
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 |
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()
|