Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save esenthil2018/9ff2500973f5848ef37c2a84a7ec77d9 to your computer and use it in GitHub Desktop.
Save esenthil2018/9ff2500973f5848ef37c2a84a7ec77d9 to your computer and use it in GitHub Desktop.
myapp
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import tensorflow as tf
import numpy as np
import streamlit as st
from PIL import Image
import requests
from io import BytesIO
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Location Image Classifier")
st.text("Provide URL of Location Image for image classification")
@st.cache(allow_output_mutation=True)
def load_model():
model = tf.keras.models.load_model('/app/models/')
return model
with st.spinner('Loading Model Into Memory....'):
model = load_model()
classes = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
def decode_img(image):
img = tf.image.decode_jpeg(image, channels=3)
img = tf.image.resize(img,[150,150])
return np.expand_dims(img, axis=0)
path = st.text_input('Enter Image URL to Classify.. ','https://storage.googleapis.com/image_classification_2021/Glacier-Argentina-South-America-blue-ice.JPEG')
if path is not None:
content = requests.get(path).content
st.write("Predicted Class :")
with st.spinner('classifying.....'):
label =np.argmax(model.predict(decode_img(content)),axis=1)
st.write(classes[label[0]])
st.write("")
image = Image.open(BytesIO(content))
st.image(image, caption='Classifying Image', use_column_width=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment