import streamlit as st import keras import numpy as np from PIL import Image st.set_page_config(layout="wide") #title st.title('Crossing Identifier') #header st.header('Choose whether you\'d like to enter a latitude/longitude coordinates, or upload a satellite image.') state = st.session_state if "dict_options" not in state: state.dict_options = {} if "submitted" not in state: state.submitted = False options = ["option1", "option2", "option3", "option4"] col1, col2, col3 = st.columns(3) with col1.form("my_form"): new_country = st.text_input("New country") submit_button = st.form_submit_button( label="Add new country", on_click=lambda: state.update(submitted=True) ) if state.submitted: state.dict_options[new_country] = col2.multiselect( f"Select the options you want for {new_country}", options, default=options[:2], ) col2.write(state.dict_options) #divide app into two columns col1, col2 = st.columns(2) #load model and initialize image size required by model. uploaded images are resized to indicated size loaded_model = keras.models.load_model("0.0008-0.92.keras") img_height = 640 img_width = 640 #place to enter #place to enter coordinates (or upload) and display image with col1: enter_coords = st.button("Enter Coordinates") if enter_coords: st.write(":smile:") upload_img = st.button("Upload an Image") if enter_coords: st.write("ok") st.header('Please upload a satellite image, or enter a latitude/longitude pair') img_buffer = st.file_uploader("Upload a satellite image file (format: .png, .jpeg, or .jpg).",type=['png', 'jpeg', 'jpg']) if img_buffer is not None: st.image(img_buffer, use_column_width = True) #place to display prediction result with col2: if img_buffer is not None: st.header('Result') img = Image.open(img_buffer).convert("RGB") img_array = np.array(img) batch_size = 1 img_array = np.reshape(img_array,[batch_size,img_height,img_width,3]) result = loaded_model.predict(img_array) st.write("Your prediction is:") st.write(f"{np.round(result[0][0]*100,decimals=2)}% chance of no crossing") st.write(f"{np.round(result[0][1]*100,decimals=2)}% chance of at least one crossing")