Spaces:
Runtime error
Runtime error
nbiish
commited on
Commit
•
d16b422
1
Parent(s):
a15e6be
initial space commit
Browse files- app.py +54 -0
- requirements.txt +10 -0
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### TODO:
|
2 |
+
# 1. gradio interface to upload image
|
3 |
+
# 2. use image ai model to determine if feather is from protected-birds.csv file
|
4 |
+
# 3. prompt user to verify results if bird is protected for themselves before making a report
|
5 |
+
# 4. list possible protected birds from list of protected-birds.csv file along with confidence score
|
6 |
+
# 5. output the result in a table format along with search queries for each bird for user to verify
|
7 |
+
# 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
|
8 |
+
|
9 |
+
import gradio as gr
|
10 |
+
import pandas as pd
|
11 |
+
import numpy as np
|
12 |
+
import os
|
13 |
+
from PIL import Image
|
14 |
+
import requests
|
15 |
+
from io import BytesIO
|
16 |
+
from imageai.Prediction import ImagePrediction
|
17 |
+
import csv
|
18 |
+
|
19 |
+
# Load the protected-birds.csv file
|
20 |
+
protected_birds = pd.read_csv('protected-birds.csv')
|
21 |
+
protected_birds = protected_birds.dropna()
|
22 |
+
protected_birds = protected_birds['Common Name'].str.lower().values
|
23 |
+
|
24 |
+
# Load the image ai model
|
25 |
+
model = ImagePrediction()
|
26 |
+
model.setModelTypeAsResNet()
|
27 |
+
model.setModelPath("resnet50_weights_tf_dim_ordering_tf_kernels.h5")
|
28 |
+
model.loadModel()
|
29 |
+
|
30 |
+
# Function to check if the feather is from a protected bird
|
31 |
+
def check_feather(image):
|
32 |
+
# Load the image
|
33 |
+
response = requests.get(image)
|
34 |
+
img = Image.open(BytesIO(response.content))
|
35 |
+
img.save('image.jpg')
|
36 |
+
|
37 |
+
# Make a prediction
|
38 |
+
model_predictions, probabilities = model.predictImage('image.jpg', result_count=5)
|
39 |
+
|
40 |
+
# Check if the feather is from a protected bird
|
41 |
+
protected = False
|
42 |
+
protected_birds_list = []
|
43 |
+
for bird in protected_birds:
|
44 |
+
for prediction in model_predictions:
|
45 |
+
if bird in prediction.lower():
|
46 |
+
protected = True
|
47 |
+
protected_birds_list.append([bird, prediction, probabilities[model_predictions.index(prediction)]])
|
48 |
+
|
49 |
+
return protected, protected_birds_list
|
50 |
+
|
51 |
+
# Gradio interface
|
52 |
+
image = gr.inputs.Image()
|
53 |
+
gr.Interface(fn=check_feather, inputs=image, outputs="text").launch()
|
54 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
Pillow
|
5 |
+
requests
|
6 |
+
imageai
|
7 |
+
tensorflow>=2.4.0
|
8 |
+
pytest
|
9 |
+
mock
|
10 |
+
coverage
|