Spaces:
Runtime error
Runtime error
Commit
·
9346f85
1
Parent(s):
ae9e937
Upload 2 files
Browse files- requirements.txt +6 -0
- stream_app.py +64 -0
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|
| 4 |
+
gradio
|
| 5 |
+
huggingface_hub
|
| 6 |
+
Pillow
|
stream_app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from huggingface_hub import from_pretrained_keras
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
burmese_snake_classifer_pretrained = from_pretrained_keras('jojo-ai-mst/burmese_snake_classifier')
|
| 8 |
+
snake_nonsnake_classifier_pretrained = from_pretrained_keras('jojo-ai-mst/snake_nonsnake_classifier')
|
| 9 |
+
|
| 10 |
+
class_names = ['Bungarus fasciatus (Banded Krait)', 'Chrysopelea ornata (Golden Tree Snake)', "Daboia siamensis (Eastern Russell's viper)", 'Fowlea piscator (Checkered Keelback)', 'Laticauda colubrina (Sea Snake)', 'Lycodon aulicus (Wolf Snake)', 'Naja kaouthia(Cobra)', 'Ophiophagus_hannah(King Cobra)', 'Rhadophis helleri (Heller Red necked keelback)', 'Trimeresurus_sp (Asian Palm Pit vipers)']
|
| 11 |
+
|
| 12 |
+
def is_snake(img_array):
|
| 13 |
+
prediction = snake_nonsnake_classifier_pretrained.predict(img_array)
|
| 14 |
+
score = prediction[0][0]
|
| 15 |
+
if score < 0.2:
|
| 16 |
+
return False
|
| 17 |
+
return True
|
| 18 |
+
|
| 19 |
+
def classify_snake(img_array):
|
| 20 |
+
predictions = burmese_snake_classifer_pretrained.predict(img_array)
|
| 21 |
+
score = tf.nn.softmax(predictions[0])
|
| 22 |
+
|
| 23 |
+
result = "This image most likely belongs to {} with a {:.2f} percent confidence.".format(class_names[np.argmax(score)], 100 * np.max(score))
|
| 24 |
+
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
def predict_img(input_img):
|
| 28 |
+
img_array = np.expand_dims(input_img, 0)
|
| 29 |
+
if is_snake(img_array):
|
| 30 |
+
return classify_snake(img_array)
|
| 31 |
+
else:
|
| 32 |
+
return "This image is not containing snake or poorly containing snake that MMDeepSnake can't detect snake in the image"
|
| 33 |
+
|
| 34 |
+
st.title("MM DeepSnake")
|
| 35 |
+
st.subheader('MM DeepSnake AI classifies snakes species in Myanmar, currently only 10 species')
|
| 36 |
+
|
| 37 |
+
with st.sidebar:
|
| 38 |
+
st.write("""
|
| 39 |
+
At the moment, we support
|
| 40 |
+
- Trimeresurus_sp (Asian Palm Pit vipers) - မြွေစိမ်းမြီးခြောက်
|
| 41 |
+
- Rhadophis helleri (Heller Red necked keelback) - လည်ပင်းနီမြွေ
|
| 42 |
+
- Lycodon aulicus (Wolf Snake) - မြွေဝံပုလွေ
|
| 43 |
+
- Fowlea piscator (Checkered Keelback) - ရေမြွေဗျောက်မ
|
| 44 |
+
- Daboia siamensis (Eastern Russell's viper) - မြွေပွေး
|
| 45 |
+
- Chrysopelea ornata (Golden Tree Snake) - ထန်းမြွေ
|
| 46 |
+
- Bungarus fasciatus (Banded Krait) - ငန်းတော်ကြား
|
| 47 |
+
- Ophiophagus hannah(King Cobra) - တောကြီးမြွေဟောက်
|
| 48 |
+
- Laticauda colubrina (Sea Snake) - ဂျက်မြွေ
|
| 49 |
+
- Naja kaouthia (Cobra) - မြွေဟောက်
|
| 50 |
+
""")
|
| 51 |
+
|
| 52 |
+
uploaded_file = st.file_uploader("Upload Snake Image", type=['png', 'jpg','jpeg'], accept_multiple_files=False,label_visibility="visible")
|
| 53 |
+
|
| 54 |
+
if uploaded_file is not None:
|
| 55 |
+
original = Image.open(uploaded_file)
|
| 56 |
+
st.image(original, use_column_width=True)
|
| 57 |
+
|
| 58 |
+
original = original.resize((300,300))
|
| 59 |
+
|
| 60 |
+
img= np.array(original.convert('RGB'))
|
| 61 |
+
|
| 62 |
+
result = predict_img(img)
|
| 63 |
+
|
| 64 |
+
st.write(result)
|