### TODO: # 1. gradio interface to upload image # 2. use image ai model to determine if feather is from protected-birds.csv file # 3. prompt user to verify results if bird is protected for themselves before making a report # 4. list possible protected birds from list of protected-birds.csv file along with confidence score # 5. output the result in a table format along with search queries for each bird for user to verify # 6. prompt user to make a report they are confident the feather in the image is from a protected bird along with the link to https://www.fws.gov/contact-us import gradio as gr import pandas as pd import numpy as np import os from PIL import Image import requests from io import BytesIO from imageai.Prediction import ImagePrediction import csv # Load the protected-birds.csv file protected_birds = pd.read_csv('protected-birds.csv') protected_birds = protected_birds.dropna() protected_birds = protected_birds['Common Name'].str.lower().values # Load the image ai model model = ImagePrediction() model.setModelTypeAsResNet() model.setModelPath("resnet50_weights_tf_dim_ordering_tf_kernels.h5") model.loadModel() # Function to check if the feather is from a protected bird def check_feather(image): # Load the image response = requests.get(image) img = Image.open(BytesIO(response.content)) img.save('image.jpg') # Make a prediction model_predictions, probabilities = model.predictImage('image.jpg', result_count=5) # Check if the feather is from a protected bird protected = False protected_birds_list = [] for bird in protected_birds: for prediction in model_predictions: if bird in prediction.lower(): protected = True protected_birds_list.append([bird, prediction, probabilities[model_predictions.index(prediction)]]) return protected, protected_birds_list # Gradio interface image = gr.inputs.Image() gr.Interface(fn=check_feather, inputs=image, outputs="text").launch()